Inline elements let you style or organize small parts of text or content without breaking the flow of the paragraph or line.
Inline elements in HTML
<tagname>content</tagname>
<strong>Important</strong>
<a href="https://example.com">Visit site</a>
<em>Note</em>
<span style="color: red;">Red text</span>
This example shows different inline elements inside paragraphs. The text stays on the same line except where it naturally wraps. The strong and em tags style words bold and italic. The a tag creates a clickable link with an accessible label. The span adds a yellow background highlight. The img tag inserts a small icon aligned with the text.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Inline Elements Example</title> <style> .highlight { background-color: yellow; } </style> </head> <body> <p>This is a <strong>bold</strong> word, an <em>italic</em> word, and a <a href="https://example.com" aria-label="Example website">link</a> inside a sentence.</p> <p>Here is a <span class="highlight">highlighted text</span> inside the paragraph.</p> <p>And here is an inline image <img src="https://via.placeholder.com/20" alt="small icon" style="vertical-align: middle;"> inside text.</p> </body> </html>
Inline elements do not cause line breaks, so they keep content flowing smoothly.
Use aria-label on links or images for better accessibility.
Images inside text should have alt text and be sized appropriately to blend well.
Inline elements style or organize small parts of content without breaking lines.
Common inline tags include strong, em, a, span, and img.
They keep text flowing naturally and help make content clearer and more interactive.
Practice
Solution
Step 1: Understand inline vs block elements
Inline elements do not start on a new line and only take up as much width as necessary.Step 2: Identify the inline element among options
<span>is an inline element, while<div>,<section>, and<article>are block elements.Final Answer:
<span> -> Option DQuick Check:
Inline element = <span> [OK]
- Confusing <span> with <div>
- Thinking <section> is inline
- Assuming all tags are inline
Solution
Step 1: Identify inline tags for italic style
The<em>tag is used to emphasize text, typically rendering it in italics.Step 2: Check other options
<i>also italicizes but<em>is preferred for meaning;<strong>is for strong importance;<italic>is not a valid tag.Final Answer:
<em>Text</em> -> Option CQuick Check:
Italic inline tag = <em> [OK]
- Using non-existent <italic> tag
- Confusing <strong> with italic
- Choosing <i> over <em> without meaning
<p>Hello <strong>World</strong>!</p>
Solution
Step 1: Understand the tag effect
The<strong>tag makes text bold and emphasizes it.Step 2: Visualize the output
The word 'World' inside<strong>will appear bold, while the rest remains normal.Final Answer:
Hello World! (with 'World' bolded) -> Option AQuick Check:
<strong> = bold text [OK]
- Thinking <strong> italicizes text
- Expecting tags to show as text
- Assuming whole sentence is bold
<p>Click <a href='https://example.com'>here</p></a>
Solution
Step 1: Check tag nesting rules
Inline elements like<a>must be properly opened and closed inside block elements like<p>.Step 2: Identify the error in closing tags
The<a>tag is opened inside<p>but closed after</p>, which breaks proper nesting.Final Answer:
The <a> tag is not closed properly inside <p> -> Option BQuick Check:
Inline tags must close before block ends [OK]
- Closing <a> after
- Thinking <p> can't contain inline tags
- Ignoring tag nesting order
Solution
Step 1: Understand the purpose of inline styling
To style small parts of text without breaking lines, an inline element that does not create new blocks is needed.Step 2: Identify the best inline element for styling
<span>is a generic inline container used to apply styles or classes to parts of text without affecting layout.Final Answer:
<span> -> Option AQuick Check:
Use <span> for inline styling [OK]
- Using block tags like <div> for inline styling
- Confusing <section> or <article> with inline tags
- Trying to style text without a container
Ready to prove it?
Pass the test and this pattern moves unknown
