HTML can directly contain SVG for graphics and MathML for mathematical expressions. These use their own element vocabularies inside an HTML document.
What You Need to Know
The browser parses nested SVG and MathML using special rules. Do not assume their case rules, self-closing syntax, or available attributes work exactly like ordinary HTML tags.
SVG and MathML have their own element and attribute rules inside an HTML page; do not assume every HTML parsing rule applies inside them.
The goal is not to collect as many tags as possible. Pick the element that best describes what the content really is.
Example: See It in Action
Try this markup in a fresh practice file. The next section explains the parts worth paying attention to.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<article>
<h2>Shapes and formulas</h2>
<svg viewBox="0 0 100 50" aria-label="Blue rectangle" role="img">
<rect width="100" height="50" fill="blue"/>
</svg>
<math><msup><mi>x</mi><mn>2</mn></msup></math>
</article>
Let’s Understand the Example
- Article marks a piece that could make sense on its own, such as a news post or recipe.
- An h2 starts a major section beneath the page topic.
- Svg describes vector graphics that stay sharp when resized.
- Aria-label supplies an accessible name when a visible label is unavailable or inadequate.
- Role describes an accessibility role when native HTML semantics do not already provide it.
- Width gives a useful size hint; for images, accurate dimensions help the browser reserve space.
You should see a readable heading and its related content. The heading level tells readers how the ideas fit together, not merely how large the letters look.
What Should You See?
The page should display “Shapes and formulas” as a heading, followed by its related content. Change the heading text and refresh the browser to see the result.
Read only the headings, from top to bottom. Do they tell a sensible story? If not, move sections or choose levels that match the content.
Try It Yourself
- Change the rectangle's width and read the mathematical expression aloud.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Trying to write a regular HTML paragraph as if it were an SVG graphic element.
- Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.
Key Takeaways
- HTML can directly contain SVG for graphics and MathML for mathematical expressions.
- Article marks a piece that could make sense on its own, such as a news post or recipe.
- SVG and MathML have their own element and attribute rules inside an HTML page; do not assume every HTML parsing rule applies inside them.