I've just realized that both following ways work. I'm not sure if I can omit label
and just put [type="checkbox"]
.
I'm confused because the documentation is different than tutorials and people's code. Some people use elements, some omit them.
Does it play an important role? Is there any difference between these two versions?
I’d be grateful for some advice from a more experienced person.
<form action="/submit-your-photo" id="your-photo">
<p>How would you describe yourself?</p>
<label><input type="checkbox" name="personality" checked> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Energetic</label><br>
<input type="text" placeholder="your photo URL" required>
<button type="submit">Submit</button>
</form>
CSS:
I version:
input[type="checkbox"]{
margin: 20px 10px;
}
II version:
[type="checkbox"]{
margin: 20px 10px;
}