I want to create my first web page but I encountered a problem.
I have the following code:
<img src="img/logo.png" alt="logo" /> <h1>My website name</h1>
I'd like to know how to make the logo and the H1 to be in the same line. Thanks!
Just stick the img tag inside the h1 tag as part of the content.
You can place an image inside an h1 element, but not quite like that … the alt attribute is mandatory. Show activity on this post. To summarize the other answers, it is W3C valid to use an <img> inside an <h1> . Though to be completly valid you should add an alt attribute to your image, because it's mandatory.
As example (DEMO):
HTML:
<div class="header"> <img src="img/logo.png" alt="logo" /> <h1>My website name</h1> </div>
CSS:
.header img { float: left; width: 100px; height: 100px; background: #555; } .header h1 { position: relative; top: 18px; left: 10px; }
DEMO
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