Heading classes help you quickly style titles and headings on your webpage with consistent sizes and spacing.
Heading classes in Bootsrap
<h1 class="display-1">Heading text</h1> <h2 class="display-2">Heading text</h2> <h3 class="display-3">Heading text</h3> <h4 class="display-4">Heading text</h4>
Use display-1 to display-4 classes for large, attention-grabbing headings.
These classes adjust font size and weight automatically for you.
display-1 class.<h1 class="display-1">Big Heading</h1>
display-3.<h2 class="display-3">Medium Heading</h2>
display-4.<h3 class="display-4">Smaller Heading</h3>
<h4>Normal Heading</h4>
This example shows how to use Bootstrap's heading classes display-1 to display-4 for big headings. The last heading uses the normal h5 tag without a display class.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Heading Classes Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container py-4"> <h1 class="display-1">Display 1 Heading</h1> <h2 class="display-2">Display 2 Heading</h2> <h3 class="display-3">Display 3 Heading</h3> <h4 class="display-4">Display 4 Heading</h4> <h5>Normal h5 Heading</h5> </main> </body> </html>
Heading classes like display-1 are meant for large, eye-catching titles, not for regular paragraph text.
Always use semantic heading tags (h1 to h6) for accessibility, even when adding display classes.
Bootstrap's display classes adjust font size and weight but keep the heading's semantic meaning.
Use Bootstrap heading classes display-1 to display-4 for big, styled headings.
These classes make headings look consistent and attractive without extra CSS.
Keep using proper heading tags for good structure and accessibility.
Practice
Solution
Step 1: Understand Bootstrap display classes
Bootstrap provides display classes fromdisplay-1todisplay-4, wheredisplay-1is the largest size.Step 2: Identify the largest display class
Among the options,display-1is the biggest heading style.Final Answer:
display-1 -> Option DQuick Check:
Largest display heading = display-1 [OK]
- Confusing
h1tag with Bootstrap display classes - Choosing
display-4thinking higher number means bigger - Using
leadwhich styles paragraphs, not headings
h2 element?Solution
Step 1: Check correct class syntax
Bootstrap display classes use the formatdisplay-1todisplay-4and must be added inside theclassattribute.Step 2: Validate each option
<h2 class='display-2'>Hello</h2>usesclass='display-2'correctly.<h2 display-2>Hello</h2>missesclass=.<h2 class='display2'>Hello</h2>uses wrong class namedisplay2.<h2 class='display-5'>Hello</h2>uses invalid classdisplay-5which doesn't exist.Final Answer:
<h2 class='display-2'>Hello</h2> -> Option AQuick Check:
Use class='display-x' with x from 1 to 4 [OK]
- Forgetting to use class attribute
- Using wrong class names without dash
- Using non-existent display classes like display-5
<h3 class='display-3'>Title</h3> compared to <h3>Title</h3> in Bootstrap?Solution
Step 1: Understand Bootstrap display classes effect
Display classes increase font size and weight to make headings stand out more than default heading tags.Step 2: Compare default
Usingh3withdisplay-3display-3onh3makes the text bigger and bolder than the normalh3style.Final Answer:
The text will be larger and bolder with display-3 class. -> Option BQuick Check:
Display classes enlarge and bold headings [OK]
- Thinking display classes make text smaller
- Assuming no style change happens
- Confusing display classes with italic or color styles
<h1 class='display-5'>Welcome</h1>Solution
Step 1: Verify Bootstrap display classes range
Bootstrap display classes only go fromdisplay-1todisplay-4. There is nodisplay-5.Step 2: Check other options for validity
Theh1tag cannot have classes. is false becauseh1can have classes. The class name should bedisplay_5with underscore. is incorrect because Bootstrap uses dashes, not underscores. The text 'Welcome' should be inside aspan. is unnecessary; text can be directly insideh1.Final Answer:
The class display-5 does not exist in Bootstrap. -> Option CQuick Check:
Display classes only from display-1 to display-4 [OK]
- Using non-existent display classes like display-5
- Thinking class names can have underscores
- Believing headings can't have classes
h4 for accessibility. Which is the best way to do this?Solution
Step 1: Understand semantic vs visual roles
For accessibility, the heading tag (h4) should reflect the document structure. Visual size can be changed with Bootstrap classes.Step 2: Evaluate options for semantic correctness and styling
<h4 class='display-1'>Big Heading</h4>keepsh4semantic tag and appliesdisplay-1for large style.<h1 class='display-4'>Big Heading</h1>usesh1which changes semantics.<div class='display-1'>Big Heading</div>usesdivwhich is not semantic heading.<h4 style='font-size: 3rem;'>Big Heading</h4>uses inline style, not Bootstrap class.Final Answer:
<h4 class='display-1'>Big Heading</h4> -> Option AQuick Check:
Use semantic tag + display class for size [OK]
- Changing heading tag to bigger one for size
- Using non-semantic tags for headings
- Relying on inline styles instead of Bootstrap classes
Ready to prove it?
Pass the test and this pattern moves unknown
