7 useful HTML attributes you may not know
Tags: webdev, html, beginners, productivity
Published: 2021-09-22 15:28:51

HTML is the cornerstone of web development. Yet, many aspiring programmers merely skim the surface and move on to CSS, JS, etc, missing its entire potential. 

This is a list of HTML attributes that many beginners don't know, but that can be helpful. 

Please, let me know in the comments if you would like to add any other attribute to the list and I'll check it out ;)

&nbsp;

##1) Multiple 
&nbsp;
The `multiple` attribute allows the user to enter multiple values on an `<input>`. It is a boolean attribute valid for file or email input types and the `<select>` element.

For an email input, if and only if the multiple attribute is specified, the value can be a list of comma-separated email addresses. Any whitespace is removed from each address in the list.

For a file input, the user can select multiple files in the as usual (holding down Shift or Crtl).

```html 
<input type="file" multiple>
```
&nbsp;

##2) Accept
&nbsp;
The `<input>` element has the `accept` attribute that allows you to specify the types of files the user can upload.

You need to pass it a string containing a comma-separated list of unique file type specifiers.

You can also use it to specify only audio, image, or video format.

```html 
<input type="file" accept=".png, .jpg">
```
&nbsp;

##3) Contenteditable
&nbsp;
`contenteditable` is a global attribute (common to all HTML elements) that makes the HTML content editable by the user or not. However, be careful with changes only made to visible content vs the DOM content.

```html 
<div contenteditable="true">I'm a cool editable div ;)</div>
```

![editable div](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65q8ryqz9dbji04mbc0s.gif)

&nbsp;

##4) Spellcheck 
&nbsp;
The `spellcheck` is another global attribute that you can use to check spelling and grammar on HTML elements such as input fields and other editable elements. 

Note: Typically non-editable elements are not checked for spelling errors, even if the spellcheck attribute is set to true and the browser supports spellchecking.

```html 
<p contenteditable="true" spellcheck="true">
Thanks furr checkinng my speling :)</p>
```
&nbsp;

##5) Translate
&nbsp;
`translate` tells the browser whether the content should be translated or not. 

For instance, you can use it to prevent Google Translate from automatically trying to translate your company's or brand's name.

```html 
<footer><p translate="no">LearnPine</p></footer>
```
&nbsp;

##6) Poster
&nbsp;
Use the `poster` attribute to specify an image to be shown while the video is downloading, or until the user hits the play button. 

If the image isn't specified, nothing is displayed until the first frame is available, then the first frame is shown as the poster frame.

```html 
<video controls 
src="https://bit.ly/3nWh78w"
poster="posterImage.png">
</video>
```

&nbsp;

##7) Download
&nbsp;
Use the `download` attribute combined with an `<a>` element to instruct browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file.

You can also specify the file name.

```html 
<a href="index.html" download="fileName">Download me :)</a>
```

&nbsp;
&nbsp;
## About me, let's connect! 👋👩‍💻
&nbsp;
I'm an avid learner and I love sharing what I know. I teach coding live for free 👉 [here](https://learnpine.com "here") and I share coding tips on [my Twitter account](https://twitter.com/simonpaix) . If you want more tips, you can follow me 😁
&nbsp;
&nbsp;