21 HTML Tips You Must Know About(๋ฌด์กฐ๊ฑด ์์์ผ ํ๋ 21๊ฐ์ HTML ํ)
๐ก ์๋ณธ๊ธ: https://dev.to/devshefali/21-html-tips-you-must-know-about-55j7
21 HTML Tips You Must Know About
In this post, Iโll share 21 HTML Tips with code snippets that can boost your coding skills. Letโs...
dev.to
์ด ๊ฒ์๋ฌผ์์๋ ์ฝ๋ฉ ๊ธฐ์ ์ ํฅ์์ํฌ ์ ์๋ ์ฝ๋ ์กฐ๊ฐ๊ณผ ํจ๊ป 21๊ฐ์ง HTML ํ์ ๊ณต์ ํ๊ฒ ์ต๋๋ค.
๊ทธ๋ผ ๋ฐ๋ก ๋ฐ์ด๋ค์ด๊ฐ ๋ณผ๊น์.๐
์ฐ๋ฝ์ฒ ๋งํฌ ๋ง๋ค๊ธฐ
HTML์ ์ฌ์ฉํ์ฌ ํด๋ฆญ์ด ๊ฐ๋ฅํ ์ด๋ฉ์ผ, ์ ํ ํตํ ๋ฐ SMS ๋งํฌ๋ฅผ ๋ง๋ค์ ์์ต๋๋ค.
<!-- Email link -->
<a href="mailto:name@example.com"> Send Email </a>
<!-- Phone call link -->
<a href="tel:+1234567890"> Call Us </a>
<!-- SMS link -->
<a href="sms:+1234567890"> Send SMS </a>
์ ์(Collapse)์ ์๋ ์ฝํ ์ธ ๋ง๋ค๊ธฐ
์นํ์ด์ง์์ ์ ์ ์ ์๋ ์ฝํ ์ธ ๋ฅผ ํฌํจํ๋ ค๋ ๊ฒฝ์ฐ <details> ๋ฐ <summary> ํ๊ทธ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
<details> ํ๊ทธ๋ ์จ๊ฒจ์ง ์ฝํ ์ธ ์ ๋ํ ์ปจํ ์ด๋๋ฅผ ์์ฑํ๋ ๋ฐ๋ฉด, <summary> ๋ ํด๋น ์ฝํ ์ธ ์ ํ์ ์ฌ๋ถ๋ฅผ ์ ํํ ์ ์๋ ํด๋ฆญ ๊ฐ๋ฅํ ๋ผ๋ฒจ์ ์ ๊ณตํฉ๋๋ค.
<details>
<summary>Click to expand</summary>
<p>This content can be expanded or collapsed.</p>
</details>
์๋ฏธ์ ์ธ(Semantic) ์์ ํ์ฉ
์น์ฌ์ดํธ์ ๋ํด ๋น์๋ฏธ์ ์ธ ์์๋ณด๋จ ์๋ฏธ์ ์ธ(Semantic)ํ ์์๋ฅผ ์ฌ์ฉํ์ธ์. ์ฝ๋๋ฅผ ์๋ฏธ์๊ฒ ๋ง๋ค๊ณ ๊ตฌ์กฐ, ์ ๊ทผ์ฑ ๋ฐ SEO๋ฅผ ํฅ์์ํต๋๋ค.

From ์์ ๊ทธ๋ฃนํ
<fieldset> ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ Form์ ๊ด๋ จ ์์๋ฅผ ๊ทธ๋ฃนํ ํ๊ณ <legned> ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ <fieldset> ์ ๋ชฉ์ ์ ์ํฉ๋๋ค.
์ด๋ ํจ์จ์ ์ผ๋ก ์ ๊ทผ ๊ฐ๋ฅํ Form์ ๋ง๋๋๋ฐ ์ ์ฉํฉ๋๋ค.
<form>
<fieldset>
<legend>Personal details</legend>
<label for="firstname">First name:</label>
<input type="text" id="firstname" name="firstname" />
<label for="email">Email:</label>
<input type="email" id="email" name="email" />
<label for="contact">Contact:</label>
<input type="text" id="contact" name="contact" />
<input type="button" value="Submit" />
</fieldset>
</form>
๋๋กญ๋ค์ด ๋ฉ๋ด ๊ฐ์
<optgroup> ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ HTML์ <select> ํ๊ทธ์ ์ต์ ์ ๊ทธ๋ฃนํ ํ ์ ์์ต๋๋ค.
์ด๋ ํฐ ๋๋กญ๋ค์ด ๋ฉ๋ด๋ ๊ธด ์ต์ ๋ชฉ๋ก์ผ๋ก ์์ ํ ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
<select>
<optgroup label="Fruits">
<option>Apple</option>
<option>Banana</option>
<option>Mango</option>
</optgroup>
<optgroup label="Vegetables">
<option>Tomato</option>
<option>Broccoli</option>
<option>Carrot</option>
</optgroup>
</select>
Video Presentation ๊ฐ์
poster ์์ฑ์ ์ฌ์ฉํด ๋น๋์ค๊ฐ ์ฌ์๋ ๋ ๊น์ง ์ด๋ฏธ์ง๋ฅผ ํ์ํ ์ ์์ต๋๋ค.
<video controls poster="image.png" width="500">
<source src="video.mp4" type="video/mp4 />
</video>
๋ค์ค ์ ํ ์ง์
multiple ์์ฑ์ ์ฌ์ฉํ๋ฉด <input> , <select> ์ ๋๊ฐ ์ด์์ ํ์ผ์ ์ ํ ๋ฐ ์ต์ ์ ์ ํ ํ ์ ์์ต๋๋ค.
<input type="file" multiple />
<select multiple>
<option value="java">Java</option>
<option value="javascript">JavaScript</option>
<option value="typescript">TypeScript</option>
<option value="rust">Rust</option>
</select>
์/์๋ ์ฒจ์ ํ์
<sub>, <sup> ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ๋ฅผ ๊ฐ๊ฐ ์๋ ์ฒจ์์ ์ ์ฒจ์๋ก ํ์ํ ์ ์์ต๋๋ค.

๋ค์ด๋ก๋ ๋งํฌ ์์ฑ
download ์์ฑ์ <a> ํ๊ทธ์ ๊ฐ์ด ์ฌ์ฉํ๋ฉด ๋งํฌ๋ฅผ ํด๋ฆญํ ๋ ๋งํฌ๋ ๋ฆฌ์์ค๋ฅผ ํ์ํ๋ ๋์ ์ ๋ค์ด๋ก๋ ํจ์ ์ง์ ํ ์ ์์ต๋๋ค.
<a href="document.pdf" download="document.pdf"> Download PDF </a>
์๋ ๋งํฌ์ ๋ํ ๊ธฐ๋ณธ URL ์ ์
<base> ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ ์นํ์ด์ง์ ๋ชจ๋ ์ํ URL์ ์ ์ํ ์ ์์ต๋๋ค.
์ด๋ ์น ํ์ด์ง์ ๋ชจ๋ ์ํ URL์ ๋ํ ๊ณต์ ์์์ ์ ์์ฑํ์ฌ ๋ฆฌ์์ค๋ฅผ ๋ ์ฝ๊ฒ ํ์ํ๊ณ ๋ก๋ํ ๋ ์ ์ฉํฉ๋๋ค.
Blogs
Contact
์ด๋ฏธ์ง ๋ก๋ฉ ์ ์ด
<img> ํ๊ทธ์ loading ์์ฑ์ ์ฌ์ฉํ์ฌ ๋ธ๋ผ์ฐ์ ๊ฐ ์ด๋ฏธ์ง ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ์ ์ดํ ์ ์์ต๋๋ค. ๊ฐ์ โeagerโ, โlazyโ, โautoโ๊ฐ ์์ต๋๋ค.
<img src="picture.jpg" loading="lazy">
๋ฒ์ญ ๊ธฐ๋ฅ ๊ด๋ฆฌ
transalate ์์ฑ์ ์ฌ์ฉํ์ฌ ์ฝํ ์ธ ๋ฅผ ๋ธ๋ผ์ฐ์ ์ ๋ฒ์ญ ๊ธฐ๋ฅ์ ์ฌ์ฉํด์ผ ํ๋์ง ์ฌ๋ถ๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค.
<p translate="no">
This text should not be translated.
</p>
์ต๋ ์ ๋ ฅ ๊ธธ์ด ์ค์
maxlength ์์ฑ์ ์ฌ์ฉํ๋ฉด ์ฌ์ฉ์๊ฐ ์ ๋ ฅ ํ๋์ ์ ๋ ฅํ ์ ์๋ ์ต๋ ๋ฌธ์ ์๋ฅผ ์ค์ ํ ์ ์์ต๋๋ค.
<input type="text" maxlength="4">
Setting Minimum Input Length ์ต์ ์ ๋ ฅ ๊ธธ์ด ์ค์
minlength ์์ฑ์ ์ฌ์ฉํ๋ฉด ์ ๋ ฅ ํ๋์ ๋ํ ์ต์ ๋ฌธ์ ์๋ฅผ ์ค์ ํ ์ ์์ต๋๋ค.
<input type="text" minlength="3">
์ปจํ ์ธ ํธ์ง ํ์ฑํ
contenteditable ์์ฑ์ ํตํด ์ฝํ ์ธ ๋ฅผ ํธ์ง ํ ์ ์๋ ์ฌ๋ถ๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค.
์ด๋ฅผ ํ ์ป ์ฌ์ฉ์๋ ์์ ๋ด์ ์ฝํ ์ธ ๋ฅผ ์์ ํ ์ ์์ต๋๋ค.
<div contenteditable="true">
You can edit this content.
</div>
๋ง์ถค๋ฒ ๊ฒ์ฌ ์ ์ด
<input>, <textare>, ์ฝํ ์ธ ํธ์ง ๊ฐ๋ฅ ์์์์ spellcheck ์์ฑ๊ณผ ํจ๊ป ์ฌ์ฉํ์ฌ ๋ธ๋ผ์ฐ์ ์ ๋ง์ถค๋ฒ ๊ฒ์ฌ๋ฅผ ํ์ฑํํ๊ฑฐ๋ ๋นํ์ฑํ ํ ์ ์์ต๋๋ค.
<input type="text" spellcheck="true"/>
์ ๊ทผ์ฑ ๋ณด์ฅ
alt ์์ฑ์ ์ด๋ฏธ์ง๋ฅผ ํ์ํ ์ ์๋ ๊ฒฝ์ฐ ์ด๋ฏธ์ง์ ๋ํ ๋์ฒด ํ ์คํธ๋ฅผ ์ง์ ํฉ๋๋ค.
์ ๊ทผ์ฑ๊ณผ SEO๋ฅผ ๊ฐ์ ํ๋ ค๋ฉด ํญ์ ์ด๋ฏธ์ง์ ๋ํ ์ค๋ช ์ ์ธ alt ์์ฑ์ ํฌํจํ์ธ์.
<img src="picture.jpg" alt="Description for the image">
๋งํฌ์ ๋ํ ๋์ ๋์ ์ ์
target ์์ฑ์ ์ฌ์ฉํ์ฌ ๋งํฌ๋ ๋ฆฌ์์ค๋ฅผ ํด๋ฆญํ ๋ ํ์๋ ์์น๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค.
<!-- Opens in the same frame -->
<a href="https://shefali.dev" target="_self">Open</a>
<!-- Opens in a new window or tab -->
<a href="https://shefali.dev" target="_blank">Open</a>
<!-- Opens in the parent frame -->
<a href="https://shefali.dev" target="_parent">Open</a>
<!-- Opens in the full body of the window -->
<a href="https://shefali.dev" target="_top">Open</a>
<!-- Opens in the named frame -->
<a href="https://shefali.dev" target="framename">Open</a>
์ถ๊ฐ ์ ๋ณด ์ ๊ณต
title ์์ฑ์ ์ฌ์ฉ์๊ฐ ์์ ์๋ก ๋ง์ฐ์ค๋ฅผ ๊ฐ์ ธ๊ฐ ๋ ํด๋น ์์์ ๋ํ ์ถ๊ฐ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋ ๋ฐ ์ฌ์ฉ๋ ์ ์์ต๋๋ค.
<p title="World Health Organization">WHO</p>
ํน์ ํ์ผ ํ์ ํ์ฉ
accept ์์ฑ์ ์ฌ์ฉํ์ฌ ์๋ฒ์์ ํ์ฉํ๋ ํ์ผ ํ์์ ์ง์ ํ ์ ์์ต๋๋ค. ์ด๋ <input> ํ๊ทธ์ ๊ฐ์ด ์ฌ์ฉ๋ฉ๋๋ค.
<input type="file" accept="image/png, image/jpeg" />
๋น๋์ค ๋ก๋ฉ ์ต์ ํ
<video> ํ๊ทธ์ preload ์์ฑ์ ํจ๊ป ์ฌ์ฉํ๋ฉด ๋ณด๋ค ์ํํ ์ฌ์์ ์ํด ๋น๋์ค ํ์ผ์ ๋ ๋น ๋ฅด๊ฒ ๋ก๋ฉํ ์ ์์ต๋๋ค.
<video src="video.mp4" preload="auto">
Your browser does not support the video tag.
</video>
์ค๋ ์ค๋นํ๊ฑด ์ด๊ฒ ๋ค ์ ๋๋ค.
๋์์ด ๋์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
์ฝ์ด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
์ด์ ๊ฐ์ ๋ ๋ง์ ์ฝํ ์ธ ๋ฅผ ๋ณด๋ ค๋ฉด ์ฌ๊ธฐ๋ฅผ ํด๋ฆญํ์ธ์.
X(Twiiter)์์ ์ ๋ฅผ ํ๋ก์ฐํ์๋ฉด ์น ๊ฐ๋ฐ์ ๋ํ ์ผ์ผ ํ์ ์ป์์๋ ์์ต๋๋ค.
