Tips for HTML

HTML Quick Tips

Creating a table with a Heading

There can be situation when you want your HTML table to have a heading of it's own. In such situations, we can use the colspan attribute to achieve this. Save the below code in a test.html file and open it.

A detailed example with multiple subheadings can also be found here.

Identifying when Enter key is pressed

There can be situations where you are building a Search UI, and have a button which on clicking uses the input value for further processing. Naturally, you would want that the search should also be possible when the user presses enter as well. Fortunately, this is trivially easy. All you need to do, is capture all the keypress events, and target a specific one. In our case, that would be the enter key. The modern way to do this would be to capture the key name directly, using the event.key attribute.

Older implementations might use the event.charCode event, however, it is Deprecated

Checkbox whose default state is checked

To set the default state of checkbox to be true or checked we can pass in the checked property

Show Hand when hovering over a clickable element

There are various properties you can apply to the mouse pointer. It's as simple as setting up a css style. For instance, to show a pointing hand on a clickable element such as a link,

To try this, enter the following in an html file:

There are a lot of other styles you can try. Click the heading of this tip to see them all.

Thank the author. Fork this blog.


Tagged in html