Ruby, SVG and MathML styling
Definition and purpose
CSS also styles specialized formatting systems. Ruby annotations attach short text to a base, commonly for pronunciation. SVG uses a coordinate system and paint properties for shapes. MathML represents mathematical structure and has specialized layout behavior for formulas. Their HTML markup retains the semantics; CSS controls presentation.
Annotation position and size
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #r { ruby-position: under; } #rt { font-size: 10px; } </style> </head> <body> <p lang="ja"> <ruby id="r"> 山 <rt id="rt">やま</rt> </ruby> </p> <svg width="100" height="60" viewBox="0 0 100 60" role="img" aria-label="Outlined circle"> <circle id="shape" cx="50" cy="30" r="20" fill="gray"/> </svg> <p> Fraction: <math id="m"> <mfrac> <mn>1</mn> <mn>2</mn> </mfrac> </math> </p> </body></html>The annotation is requested below horizontal base text, with a 10px font size.
Syntax and mental model
ruby-position: over or under changes which side of the base receives the annotation in horizontal text; writing mode changes the physical interpretation. Inline SVG presentation attributes participate in the cascade, so CSS fill and stroke can override them. In MathML, math-style: compact requests a layout that tends to reduce logical height, while normal requests ordinary display-style layout. Actual formula metrics depend on mathematical font support. The samples test computed styles, not linguistic shaping or mathematical glyph metrics.
Style vector paint and formula
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #shape { fill: navy; stroke: teal; stroke-width: 3px; } #m { math-style: normal; } </style> </head> <body> <p lang="ja"> <ruby id="r"> 山 <rt id="rt">やま</rt> </ruby> </p> <svg width="100" height="60" viewBox="0 0 100 60" role="img" aria-label="Outlined circle"> <circle id="shape" cx="50" cy="30" r="20" fill="gray"/> </svg> <p> Fraction: <math id="m"> <mfrac> <mn>1</mn> <mn>2</mn> </mfrac> </math> </p> </body></html>CSS overrides gray fill and requests normal math layout.
Common mistakes
Do not replace Ruby or MathML structures with positioned spans simply to reproduce appearance. Do not assume a CSS rule on an img element can style paths inside an external SVG image; the inline SVG example is part of the document DOM.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Lists, counters and generated content. Next lesson: Image functions and object positioning.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Ruby, SVG and MathML styling — knowledge check
Five questions on ruby, svg and mathml styling.
What does Ruby markup represent?
Which CSS property controls the annotation side?
Which property paints the inside of an inline SVG circle?
What does math-style: compact request?
Why preserve MathML structure?