DEV Community

The 6 most common mistakes developers when writing HTML and CSS

Stas Melnikov on November 10, 2019

The placeholder attribute instead of the label element Please, stop using the placeholder attribute instead of the label element. People...
Collapse
 
jlipinski3 profile image
Josh Lipinski

Nice, some good points. This is really short-sighted though: "Using display: block and position: absolute (fixed) together". In all browsers? In one browser? What if a user agent is configured differently? Chrome makes changes to their user agent stylesheet all the time. I would never discourage someone to leave out something as important as a display property if they want to explicitly define it. Sure, there are some we've all gotten used to over the years, but by no means would I consider this a "mistake". What if said element is a table and said user wants to absolutely position it as a block element? Be careful with how you are categorizing these as "mistakes".

Collapse
 
glebkema profile image
Gleb Kemarsky • Edited

I have not thought about this before. So I checked it with a CodePen and found this sentence in the Specification:

An absolutely positioned box establishes a new containing block for normal flow children and absolutely (but not fixed) positioned descendants.

I assume that these words about "new containing block" force browser developers to display absolutely positioned pseudo-element as a block.

Collapse
 
alohci profile image
Nicholas Stimpson • Edited

No they don't. display:inline-block, display:table-cell and display:list-item all establish containing blocks, so any of those would also be consistent with that sentence from the spec. What you are looking for is section 9.7 Relationships between 'display', 'position', and 'float', step 2

Collapse
 
melnik909 profile image
Stas Melnikov

In Chrome. IE, Edge, Firefox, Safari, Android, Safari on iOS, UC Browser, Samsung

Collapse
 
shnrmn profile image
Shawn Norman

Any mistakes authors when writing headlines?

Collapse
 
kamcio profile image
kamcio • Edited

Only can judge him.

(It's all love;))

Collapse
 
dirtycode1337 profile image
Dirty-Co.de

Although I agree with most of the points, I find the headline a bit misleading - are these the "most common mistakes"? I must confess, I've never seen the "resize:none" - setting somewhere in the wild for textareas but honestly, I've also not payed attention to that :).

I definitely agree with the misusage of the placeholder - that also goes for UI designers, who misuse the placeholder already.

Relating to the usage of label, I'd recommend to extend the example with an id for the input-field and a relating for-attribute for the label-tag.
<label for="email_field">
Email:<input type="email" id="email_field" />
</label>

That makes it more relateable where the label tag relates to :).

Collapse
 
juliamattjus profile image
Julia Mattjus

Wouldn't it be nicer to wrap icons in figure elements and with a figcaption to help users with screenreaders?

Collapse
 
melnik909 profile image
Stas Melnikov

This depends on a case

Collapse
 
joellau profile image
Joel Lau

can you elaborate ?

Collapse
 
deedy profile image
Patryk Kudla

Cool! :)

Collapse
 
harispap11 profile image
Haris Papadakis

Did you count how many famous boilerplate templates have the "bad practice" hamburger menu? 🤣🤣

Awesome Article!

Collapse
 
melnik909 profile image
Stas Melnikov

I've lost count

Collapse
 
darkmyj profile image
DarkMYJ

That moment when i realized i did all of that mistakes...

Collapse
 
melnik909 profile image
Stas Melnikov

Don't worry. Now you know more and can fix it!

Collapse
 
kataras profile image
Gerasimos (Makis) Maropoulos

Nice one, good job mr Stas.

Collapse
 
melnik909 profile image
Stas Melnikov

Thank you!

Collapse
 
maroua00 profile image
Maroua00

Nice article! Helpful :)