Five HTML tips you should know!

Five HTML tips you should know!

Welcome folks!

Today I'm gonna give five tips for HTML and I hope you love these tips. Let's start!


Tip 1: Create a dropdown menu easily

<details>
  <summary>Click Me!</summary>
  <p>Hello! I am a looooooonnnnngggggg content</p>
</details>

You can create a dropdown menu with no need javascript. And you can see browser support below. Here is a demo for you :

Browser Support

ElementChromeEdgeFirefoxSafariOpera
details86-888581-82TP85

Tip 2: Let's create a selectable input

<label for="countries">Choose your country from the list:</label>
<input list="countries" name="country" id="country">

<datalist id="countries">
  <option value="United States">
  <option value="Sweden">
  <option value="Canada">
  <option value="Turkey">
  <option value="Germany">
</datalist>

Here is a demo for you :

Browser Support

ElementChromeEdgeFirefoxSafariOpera
datalist86-888581-82TP70

Tip 3: Figure Element

Normally, developers are creating img areas such that :

<img src="path/to/image" alt="About image" />
<p>Hi! I'm a text under the image. </p>

This is the wrong option we shouldn't use and google also doesn't like it in this way. That's why we need to use the figure element in these cases :

<figure>
    <img src="path/to/image" alt="About image" />
    <figcaption>
        <p>Hi! I'm a text under the image. </p>
    </figcaption>
</figure>

Here is a demo for you :

Browser Support

ElementChromeEdgeFirefoxSafariOpera
figure86-888581-82TP70

Tip 4: Editable Paragraph

Thanks to this attribute, you can edit paragraphs;

<p contenteditable="true">You can edit me! Click me!</p>

Here is a demo for you :

Browser Support

AttributeChromeEdgeFirefoxSafariOpera
contenteditable86-888581-82TP70

Tip 5: Input Pattern

You can add 'regular expression' to your inputs for validation.

<form>
  <label for="username">
    Username
    <p> 
      (letters and numbers only, no punctuation or special characters)
    </p>
  </label>

  <br>

  <input name="username" id="username" placeholder="Type and press enter" pattern="[A-Za-z0-9]+">
</form>

Here is a demo for you :

Browser Support

AttributeChromeEdgeFirefoxSafariOpera
pattern86-888581-82TP70

Conclusion

Thanks for reading through these tips. Hope you enjoyed it. Have a nice day!