I realize that in the modern day, most people use CSS to perform styling, and will have CSS define what H2 looks like.
However, please imagine that I'm trying to make my text looks like it is the default appearance of <h2>, but have it on a line with other text.
Is it possible to do this in HTML4?
Alternatively, is it possible to emulate it using CSS? Assume I am NOT setting a style on <h2> directly.
By default, all HTML headings (<h1>
to <h5>
) are displayed as block
. This means a heading will be in a separate line if there is other elements surrounding it.
You can change that with CSS by applying display: inline
to your heading. If you need it to keep some block behavior (like having a certain width, for example), you can use display: inline-block
instead.
Give a try to that:
<!DOCTYPE html>
<html>
<body>
<style>
.h2{
font-size: x-large;
font-weight: bold;
display: inline;
}
</style>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<p class="h2">This is heading 2</p>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
And you should disable your current styles applying to the current h2. For example: color: black !important; (if it's defined)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With