December 14, 2015 10:46 pm

3 HTML5 Attributes That You Should Be Using Right Now

Did you know that you can add a contenteditable attribute to almost any HTML5 tag? The attribute has two possible values – true or false. If you set the attribute to true then your users would be able to edit the content inside various different elements. You can then hook event listeners to save what they have edited and so on. You can add the attribute to almost any HTML5 tag.

Useful HTML5 Features

Here is an example of how you can use it:

Adding the attribute to an ordered list allows users to create a new list item by pressing the Enter key.

Using contenteditable to create a to-do list

Here is how we have edited the initial ordered list and added a few more list items. You can see how easy it would be to implement a to-do list with this attribute.

Now, let me show you another useful thing you can do with it:

You can add a style property to your document, set its display CSS property to block so that it would be visible on the page and set the contenteditable property to true. This would enable users to edit the rules in that style property as they wish and see the changes.

We can just edit the background color of the list items to be green and the changes would be applied to the selected elements.

Using contenteditable to allow users to change the styles of the page

The title attribute

The title attribute can be used with most elements in HTML5 and it can prove quite useful. Most browsers display it by providing a tooltip whenever the user hovers over the element that has a title attribute set. Thus, you can use it as a tooltip to provide additional information about the element.

For example, you can use with an image:

Now, whenever the users hover over our image, he will see the additional information in a tooltip (hopefully)

Image with a title tooltip

You can even add the tooltip to ordinary paragraphs:

Title tooltip for paragraphs

The placeholder attribute

When you are working with forms and inputs, it might be a good idea to add a placeholder as it is widely supported by 90.55% of the Internet users and nobody will lose if the user does not support it.
The placeholder attribute allows you to add additional information to an input when the input does not have any value and is empty.

A placeholder attribute with the value of john.doe

Whenever the user starts writing in the input, the placeholder’s value will disappear. People often make the mistake of writing things like username, password as a value to the placeholder attribute. However, you should be aware that your input should already have a label which states what needs to be written there. Therefore, it is better if you write a placeholder which gives an example of valid input, such as an example of a good username, password, email and so on.

You can use the placeholder attribute in the following way:

Author Ivan Dimov

Ivan is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling. You can find more about him at: http://www.dimoff.biz. facebook, twitter


Tutorial Categories: