<!DOCTYPE html>
    <html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
    <head>
<title>Hình ảnh img trong HTML</title>
<meta name="description" content="Hình ảnh img trong HTML - Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;www.nguoicodonvn2008.info&#x002F;vi&#x002F;news&#x002F;savefile&#x002F;kien-thuc-may-tinh&#x002F;hinh-anh-img-trong-html-10217.html">
<meta name="author" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :.">
<meta name="copyright" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :. [admin@nguoicodonvn2008.info]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.5">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Hình ảnh img trong HTML">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;www.nguoicodonvn2008.info&#x002F;vi&#x002F;news&#x002F;savefile&#x002F;kien-thuc-may-tinh&#x002F;hinh-anh-img-trong-html-10217.html">
<meta property="og:site_name" content=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.">
<meta property="og:url" content="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/hinh-anh-img-trong-html-10217.html">
<link rel="shortcut icon" href="https://nguoicodonvn2008.info/favicon.ico">
<link rel="canonical" href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/hinh-anh-img-trong-html-10217.html">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/karaoke-dual/" title="Tin Tức - Karaoke Dual" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/nhac-tre/" title="Tin Tức - Nhạc trẻ" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tru-tinh/" title="Tin Tức - Trữ tình" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/nuoc-ngoai/" title="Tin Tức - Nước ngoài" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/remix/" title="Tin Tức - Remix" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tam-su-tinh-yeu/" title="Tin Tức - Tâm sự tình yêu" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tho-suu-tam/" title="Tin Tức - Thơ sưu tầm" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/cuoc-song/" title="Tin Tức - Cuộc sống" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/phan-mem/" title="Tin Tức - Phần mềm" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/kien-thuc-may-tinh/" title="Tin Tức - Kiến thức máy tính" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/hoc-tap/" title="Tin Tức - Học tập" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tai-lieu/" title="Tin Tức - Tài liệu" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/de-thi/" title="Tin Tức - Đề thi" type="application/rss+xml">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/style.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/news.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/custom.css" type="text/css">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/bootstrap.min.js" type="text/javascript">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/style.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://nguoicodonvn2008.info/themes/default/css/news.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/custom.css">
<style type="text/css">
	body{background: #fff;}
</style>
    </head>
    <body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">.&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.</h2>
		<p class="pull-right"><a title=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;." href="https://nguoicodonvn2008.info/">https://nguoicodonvn2008.info</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Hình ảnh img trong HTML</h1>
		<ul class="list-inline">
			<li>Thứ bảy - 19/04/2025 02:16</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
		</div>
				<div class="imghome">
			<img alt="Hình ảnh img trong HTML" src="https://st.quantrimang.com/photos/image/2018/05/25/workplace.jpg" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<p style="text-align: justify;"><strong>Chỉnh kích thước ảnh trong HTML&nbsp;</strong>không khó. Dưới đây là chi tiết&nbsp;<strong>cách chỉnh kích thước ảnh HTML đơn giản</strong>&nbsp;với tất cả mọi người.</p>

<p style="text-align: justify;">Ở bài viết này, chúng ta sẽ cùng nhau tìm hiểu về HTML Image, cách thêm ảnh vào HTML, cùng với những kiến thức về triển khai và sử dụng nó qua từng ví dụ cụ thể.</p>

<p style="text-align: justify;">Trước đây, ở thời kỳ đầu, các trang web chỉ chứa nội dung dưới dạng văn bản. Điều này khiến chúng khá nhàm chán và thiếu thú vị. Theo thời gian, công nghệ lập trình ngày càng phát hiện, các trang web hiện đại giờ đã có thể nhúng được cả ảnh, thậm chí cả video bên trong để hấp dẫn nhiều lượt truy cập hơn. Tất cả nhờ những thẻ thông minh trong HTML. Với ảnh, thẻ img là không thể thiếu.</p>

<p style="text-align: justify;">Trong bài hướng dẫn dưới đây, bạn sẽ biết cách thêm ảnh vào trang web để thu hút nhiều người xem hơn cùng nhiều phương pháp chèn ảnh khác bằng img trong HTML. Về cơ bản, bạn có 2 cách:</p>

<ul>
	<li style="text-align: justify;">Qua đường link hay URL đầy đủ để truy cập file online.</li>
	<li style="text-align: justify;">Cung cấp đường dẫn file liên quan tới vị trí của file trang web hiện tại.</li>
</ul>

<h2 style="text-align: justify;">Cú pháp hình ảnh trong HTML</h2>

<p style="text-align: justify;">Trong HTML, ảnh được định nghĩa bằng thẻ&nbsp;<code>&lt;img&gt;</code></p>

<p style="text-align: justify;">Thẻ&nbsp;<code>&lt;tag&gt;</code>&nbsp;là thẻ rỗng, chỉ chứa thuộc tính và không có thẻ đóng. Thuộc tính&nbsp;<code>src</code>&nbsp;xác định URL (địa chỉ web) của hình ảnh.</p>

<pre id="pre0" style="text-align: justify;">
&lt;img src=&quot;url&quot;&gt;</pre>

<h3 style="text-align: justify;"><strong>Thuộc tính alt</strong></h3>

<p style="text-align: justify;">Thuộc tính&nbsp;<code>alt</code>&nbsp;dùng để bổ sung văn bản mô tả cho hình ảnh. Nếu vì lý do gì đó mà người dùng không thể xem được ảnh (do mạng yếu, lỗi thuộc tính&nbsp;<code>src</code>&nbsp;hoặc dùng công cụ đọc màn hình).</p>

<p style="text-align: justify;">Giá trị của thuộc tính alt là đoạn mô tả hình ảnh.</p>

<pre id="pre1" style="text-align: justify;">
&lt;img src=&quot;img_quantrimang.jpg&quot; alt=&quot;Trang web Quản trị mạng&quot;&gt;</pre>

<p style="text-align: justify;">Nếu trình duyệt không thể tìm được ảnh, nó sẽ hiển thị giá trị thuộc tính&nbsp;<code>alt.</code></p>

<p style="text-align: justify;"><strong>Lưu ý:</strong>&nbsp;thuộc tính&nbsp;<code>alt</code>&nbsp;là bắt buộc. Trang web sẽ không hợp lệ nếu hình ảnh không có thuộc tính này.</p>

<h3 style="text-align: justify;"><strong>Kích thước hình ảnh - chiều rộng và chiều cao</strong></h3>

<p style="text-align: justify;">Dùng thuộc tính&nbsp;<code>style</code>&nbsp;để xác định chiều cao và chiều rộng của hình ảnh.</p>

<pre id="pre2" style="text-align: justify;">
&lt;img src=&quot;congnghe.jpg&quot; alt=&quot;Trang web công nghệ&quot;
style=&quot;width:500px;height:600px;&quot;&gt;</pre>

<p style="text-align: justify;">Ngoài ra bạn có thể dùng thuộc tính&nbsp;<code>width</code>&nbsp;và&nbsp;<code>height.</code></p>

<pre id="pre3" style="text-align: justify;">
&lt;img src=&quot;congnghe.jpg&quot; alt=&quot;Trang web công nghệ&quot; width=&quot;500&quot; height=&quot;600&quot;&gt;</pre>

<p style="text-align: justify;">Thuộc tính&nbsp;<code>width</code>&nbsp;và&nbsp;<code>height</code>&nbsp;luôn định nghĩa chiều rộng và chiều cao của ảnh bằng pixel.</p>

<p style="text-align: justify;"><strong>Lưu ý:</strong>&nbsp;Hãy luôn chỉ định kích thước ảnh, nếu không, trang web có thể khó tải ảnh.</p>

<h3 style="text-align: justify;"><strong>Width, Height hay Style?</strong></h3>

<p style="text-align: justify;">Thuộc tính&nbsp;<code>width</code>,&nbsp;<code>height</code>&nbsp;và&nbsp;<code>style</code>&nbsp;đều hợp lệ trong HTML5. Dù vậy, nên dùng thuộc tính&nbsp;<code>style</code>&nbsp;vì nó giúp ngăn tập tin định dạng (Style Sheet) thay đổi kích thước của ảnh.</p>

<pre id="pre4" style="text-align: justify;">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;style&gt;
img {
  width:100%;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;img src=&quot;html5.gif&quot; alt=&quot;HTML5 Icon&quot; width=&quot;128&quot; height=&quot;128&quot;&gt;
&lt;img src=&quot;html5.gif&quot; alt=&quot;HTML5 Icon&quot;
style=&quot;width:128px;height:128px;&quot;&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>

<h3 style="text-align: justify;"><strong>Hình ảnh nằm trong thư mục khác</strong></h3>

<p style="text-align: justify;">Nếu không được chỉ định cụ thể, trình duyệt sẽ tìm ảnh trong cùng thư mục với trang. Nếu lưu trữ ảnh ở thư mục con, bạn phải đưa tên thư mục vào thuộc tính&nbsp;<code>src.</code></p>

<pre id="pre5" style="text-align: justify;">
&lt;img src=&quot;/photos/html5.gif&quot; alt=&quot;HTML5 Icon&quot;style=&quot;width:128px;height:128px;&quot;&gt;</pre>

<h3 style="text-align: justify;"><strong>Hình ảnh nằm ở máy chủ khác</strong></h3>

<p style="text-align: justify;">Một số trang web lưu trữ ảnh trên máy chủ riêng. Thực tế, bạn có thể truy cập hình ảnh từ bất kì địa chỉ web nào trên thế giới.</p>

<pre id="pre6" style="text-align: justify;">
&lt;img src=&quot;https://www.quantrimang.com/hinhanh/quantrimang_html.jpg&quot;alt=&quot;Quantrimang.com&quot;&gt;</pre>

<h3 style="text-align: justify;"><strong>Hình ảnh động</strong></h3>

<p style="text-align: justify;">HTML có thể hiển thị ảnh động (GIF).</p>

<pre id="pre7" style="text-align: justify;">
&lt;img src=&quot;laptrinh.gif&quot; alt=&quot;Máy tính&quot;style=&quot;width:48px;height:48px;&quot;&gt;</pre>

<h3 style="text-align: justify;"><strong>Hình ảnh đóng vai trò là đường dẫn</strong></h3>

<p style="text-align: justify;">Để dùng hình ảnh làm link, hãy đưa thẻ&nbsp;<code>&lt;img&gt;</code>&nbsp;vào trong thẻ&nbsp;<code>&lt;a&gt;</code></p>

<pre id="pre8" style="text-align: justify;">
&lt;a href=&quot;default.asp&quot;&gt;
&lt;img src=&quot;hihi.gif&quot; alt=&quot;Hướng dẫn HTML&quot;style=&quot;width:42px;height:42px;border:0;&quot;&gt;
&lt;/a&gt;</pre>

<p style="text-align: justify;"><strong>Lưu ý</strong>:&nbsp;<code>border:0;</code>&nbsp;được thêm vào để ngăn IE9 (và trở về trước) hiển thị đường viền xung quanh ảnh (khi ảnh là link).</p>

<h3 style="text-align: justify;"><strong>Hình ảnh nổi</strong></h3>

<p style="text-align: justify;">Đặc tính&nbsp;<code>float</code>&nbsp;trong CSS dùng để làm ảnh nổi về bên phải hoặc bên trái văn bản.</p>

<pre id="pre9" style="text-align: justify;">
&lt;p&gt;&lt;img src=&quot;hihi.gif&quot; alt=&quot;Mặt cười&quot;
style=&quot;float:right;width:42px;height:42px;&quot;&gt;
Hình ảnh này sẽ nổi về bên phải văn bản.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;hihi.gif&quot; alt=&quot;Mặt cười&quot;
style=&quot;float:left;width:42px;height:42px;&quot;&gt;
Hình ảnh này sẽ nổi về bên trái văn bản.&lt;/p&gt;</pre>

<h3 style="text-align: justify;"><strong>Tạo bản đồ bằng hình ảnh Image Map</strong></h3>

<p style="text-align: justify;">Thẻ&nbsp;<code>&lt;tag&gt;</code>&nbsp;được dùng để định nghĩa image-map, hình ảnh có các vùng mà khi click vào sẽ có tác động gì đó, tùy ý bạn đặt. Ví dụ, với hình ảnh sau, chúng ta sẽ đặt các vùng click tại chỗ&nbsp;<a data-google-interstitial="false" data-google-vignette="false" href="https://quantrimang.com/hoc/hinh-anh-trong-html-151448#">&nbsp;máy tính</a>, điện thoại và cốc cà phê:</p>

<div style="text-align: justify;">Linh kiện máy tính</div>

<p style="text-align: justify;"><img alt="Workplace" data-i="0" data-src="https://st.quantrimang.com/photos/image/2018/05/25/workplace.jpg" data-was-processed="true" height="379" src="https://st.quantrimang.com/photos/image/2018/05/25/workplace.jpg" usemap="#workmap" width="400" /></p>

<p style="text-align: justify;">Đây là code của file .htm đầy đủ, bạn có thể copy vào notepad, lưu thành file .htm và chạy thử trên máy.</p>

<pre id="pre10">
<code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

&lt;h2&gt;Quantrimang.com&lt;/h2&gt;
&lt;p&gt;Click vào máy tính, điện thoại hoặc cốc cà phê trong ảnh để đi đến trang mới và đọc nhiều hơn về topic:&lt;/p&gt;

&lt;img src=&quot;https://img.quantrimang.com/photos/image/2018/05/25/workplace.jpg&quot; alt=&quot;Workplace&quot; usemap=&quot;#workmap&quot; width=&quot;400&quot; height=&quot;379&quot;&gt;

&lt;map name=&quot;workmap&quot;&gt;
 &lt;area shape=&quot;rect&quot; coords=&quot;34,44,270,350&quot; alt=&quot;Computer&quot; href=&quot;https://quantrimang.com/cong-nghe&quot;&gt;
 &lt;area shape=&quot;rect&quot; coords=&quot;290,172,333,250&quot; alt=&quot;Phone&quot; href=&quot;https://quantrimang.com/ios&quot;&gt;
 &lt;area shape=&quot;circle&quot; coords=&quot;337,300,44&quot; alt=&quot;Cup of coffee&quot; href=&quot;https://quantrimang.com/cuoc-song&quot;&gt;
&lt;/map&gt;

&lt;/body&gt;
&lt;/html&gt;</code></pre>

<p style="text-align: justify;">Thuộc tính&nbsp;<code>name</code>&nbsp;của thẻ&nbsp;<code>&lt;tag&gt;</code>&nbsp;gắn tới thuộc tính usemap của thẻ&nbsp;<code>&lt;img&gt;</code>&nbsp;tạo ra mối quan hệ giữa hình ảnh và bản đồ. Phần tử&nbsp;<code>&lt;map&gt;</code>&nbsp;gồm các thẻ&nbsp;<code>&lt;area&gt;</code>&nbsp;định nghĩa những vùng có thể click vào được trong image-map.</p>

<h3 style="text-align: justify;"><strong>Hình ảnh nền</strong></h3>

<p style="text-align: justify;">Để thêm hình nền trên phần tử HTML, dùng đặc tính CSS&nbsp;<code>background-image.</code></p>

<p style="text-align: justify;">Thêm hình nền cho trang, dùng đặc tính background-image trên phần tử BODY.</p>

<pre id="pre11" style="text-align: justify;">
&lt;body style=&quot;background-image:url(&#039;bautroi.jpg&#039;)&quot;&gt;
&lt;h2&gt;Hình nền&lt;/h2&gt;
&lt;/body&gt;</pre>

<p style="text-align: justify;">Để thêm hình nền trên đoạn văn trong HTML, dùng đặc tính CSS&nbsp;<code>background-image.</code></p>

<p style="text-align: justify;">Thêm hình nền cho trang, dùng đặc tính background-image trên phần tử P.</p>

<pre id="pre12" style="text-align: justify;">
&lt;body&gt;
&lt;p style=&quot;background-image:url(&#039;bautroi.jpg&#039;)&quot;&gt;
...
&lt;/p&gt;
&lt;/body&gt;</pre>

<h3 style="text-align: justify;"><strong>Phần tử &lt;picture&gt;</strong></h3>

<p style="text-align: justify;">HTML5 có thêm phần tử&nbsp;<code>&lt;picture&gt;</code>&nbsp;để thêm sự linh hoạt khi xác định nguồn ảnh.</p>

<p style="text-align: justify;">Phần tử &lt;picture&gt; gồm số các phần tử&nbsp;<code>&lt;source&gt;,</code>&nbsp;mỗi phần tử tham chiếu tới các nguồn ảnh khác nhau. Bằng cách này trình duyệt sẽ chọn ảnh hợp với cách xem và/hoặc thiết bị hiện tại nhất.</p>

<p style="text-align: justify;">Mỗi phần tử&nbsp;<code>&lt;source&gt;</code>&nbsp;có các thuộc tính mô tả khi nào thì hợp ảnh nào nhất. Trình duyệt sẽ dùng phần tử&nbsp;<code>&lt;source&gt;</code>&nbsp;đầu tiên hợp với giá trị thuộc tính, bỏ qua các phần tử&nbsp;<code>&lt;source&gt;</code>&nbsp;sau.</p>

<p style="text-align: justify;">Hiển thị ảnh hoa hồng nếu khung nhìn tối thiểu là 650px và ảnh hoa trắng nếu tối thiểu là 465px.</p>

<pre id="pre13" style="text-align: justify;">
&lt;picture&gt;
  &lt;source media=&quot;(min-width: 650px)&quot; srcset=&quot;hoa-hồng.jpg&quot;&gt;
  &lt;source media=&quot;(min-width: 465px)&quot; srcset=&quot;hoa-trắng.jpg&quot;&gt;
  &lt;img src=&quot;hoa-xanh.jpg&quot; alt=&quot;Flowers&quot; style=&quot;width:auto;&quot;&gt;
&lt;/picture&gt;</pre>

<p style="text-align: justify;">Lưu ý: Luôn dùng phần tử&nbsp;<code>&lt;img&gt;</code>&nbsp;làm phần tử con cuối cùng trong phần tử&nbsp;<code>&lt;picture&gt;.</code>&nbsp;Phần tử&nbsp;<code>&lt;img&gt;</code>&nbsp;được các trình duyệt không hỗ trợ phần tử&nbsp;<code>&lt;picture&gt;</code>&nbsp;sử dụng, hoặc nếu không thẻ&nbsp;<code>&lt;source&gt;</code>&nbsp;nào phù hợp.</p>

<h3 style="text-align: justify;"><strong>Đọc màn hình HTML</strong></h3>

<p style="text-align: justify;">Công cụ đọc màn hình là phần mềm đọc mã HTML, chuyển đổi văn bản, cho phép người dùng “nghe” được văn bản. Công cụ đọc màn hình rất hữu ích với người khiếm thị.</p>

<h3 style="text-align: justify;">Chú thích ảnh kèm số</h3>

<p style="text-align: justify;">Nhắc tới chú thích, bạn có nhiều cách có thể thêm chú thích đi kèm với hình ảnh. Không có gì ngăn bạn làm việc này bởi nó làm việc đó rất dễ dàng trong HTML.</p>

<p style="text-align: justify;">Ví dụ:</p>

<pre id="pre14" style="text-align: justify;">
&lt;div class=&quot;figure&quot;&gt;
  &lt;img
    src=&quot;images/dinosaur.jpg&quot;
    alt=&quot;Đầu và thân của bộ xương khủng long;
             nó có một cái đầu lớn với những chiếc răng dài sắc nhọn&quot;
    width=&quot;400&quot;
    height=&quot;341&quot; /&gt;

  &lt;p&gt;Khủng long T-Rex trưng bày ở bảo tàng đại học Manchester.&lt;/p&gt;
&lt;/div&gt;</pre>

<p style="text-align: justify;">Thế là xong. Nó chứa nội dung bạn cần và có thể tạo kiểu bằng CSS. Thế nhưng có một vấn đề ở đây là không có liên kết hình ảnh với chú thích về mặt ngữ nghĩa. Điều đó có thể gây ra vấn đề về đọc màn hình. Ví dụ, khi có 50 hình ảnh và chú thích, chú thích nào sẽ đi kèm với ảnh?</p>

<p style="text-align: justify;">Một giải pháp tốt hơn là dùng các thành phần &lt;figure&gt; và &lt;figcaption&gt; trong HTML. Chúng được tạo cho mục đích này. Code mẫu như sau:</p>

<pre id="pre15" style="text-align: justify;">
&lt;figure&gt;
  &lt;img
    src=&quot;images/dinosaur.jpg&quot;
    alt=&quot;Đầu và thân của bộ xương khủng long;
             nó có một cái đầu lớn với những chiếc răng dài sắc nhọn&quot;
    width=&quot;400&quot;
    height=&quot;341&quot; /&gt;

  &lt;figcaption&gt;
   T-Rex trưng bày ở trường đại học Manchester.  &lt;/figcaption&gt;
&lt;/figure&gt;</pre>

<p style="text-align: justify;">Tóm lại, thẻ &lt;img&gt; được dùng để thêm hoặc nhúng ảnh vào một trang web. Thẻ “img” là một thẻ trống. Điều đó có nghĩa nó có thể chỉ chứa một danh sách thuộc tính và không có đóng thẻ. Việc bổ sung ảnh cải thiện chất lượng, đồng thời nâng cao cấu trúc thiết kế, hình ảnh của trang web. Hiện tại, website không trực tiếp thêm ảnh vào tảng web vì các ảnh được liên kết tới từng trang web bằng cách dùng thẻ &lt;img&gt; tiện lợi hơn và đủ không gian để chứa ảnh kích thước lớn.</p>

<p style="text-align: justify;"><strong>Những thuộc tính nổi bật của thẻ &lt;img&gt; cần ghi nhớ:</strong></p>

<ul>
	<li style="text-align: justify;"><strong>Src</strong>&nbsp;xác định đường dẫn tới ảnh.</li>
	<li style="text-align: justify;"><strong>Alt</strong>&nbsp;chứa nội dung thay thế cho ảnh.</li>
	<li style="text-align: justify;"><strong>Crossorigin</strong>&nbsp;được dùng để nhập ảnh từ các trang thứ ba, cho phép sử dụng quyền truy cập nhiều nguồn gốc với canvas.</li>
	<li style="text-align: justify;"><strong>Height</strong>&nbsp;xác định chiều cao của ảnh.</li>
	<li style="text-align: justify;"><strong>Width&nbsp;</strong>xác định chiều rộng của ảnh.</li>
	<li style="text-align: justify;"><strong>Ismap</strong>&nbsp;chỉ định một ảnh làm bản đồ ảnh bên server.</li>
	<li style="text-align: justify;"><strong>Loading</strong>&nbsp;được sử dụng để chỉ định xem trình duyệt nên trì hoãn việc tải hình ảnh cho đến khi đáp ứng một số điều kiện hay tải hình ảnh ngay lập tức.</li>
</ul>
		</div>
				<div id="author">
						<p>
				<strong>Nguồn tin:</strong>
				Quantrimang.com:
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/hinh-anh-img-trong-html-10217.html" title="Hình ảnh img trong HTML">https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/hinh-anh-img-trong-html-10217.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; .&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.
		</div>
		<div id="contact">
			<a href="mailto:admin@nguoicodonvn2008.info">admin@nguoicodonvn2008.info</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://nguoicodonvn2008.info/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
		</script>
		<div class="car-top">
  <span><img src="https://nguoicodonvn2008.info/themes/default/images/car.png" alt=""></span>
</div>
<script src="https://nguoicodonvn2008.info/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4c_e856T",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="https://nguoicodonvn2008.info/assets/js/language/vi.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/global.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/site.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/news.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/main.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/custom.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://nguoicodonvn2008.info",
            "logo": "https://nguoicodonvn2008.info/uploads/angel.gif"
        }
        </script>
<script src="https://nguoicodonvn2008.info/themes/default/js/bootstrap.min.js"></script>
<script type="text/javascript">
var $scrolltop = $('.car-top');
$scrolltop.on('click', function () {
    $('html,body').animate({
        scrollTop: 0
    }, 800);
    $(this).addClass("car-run");
    setTimeout(function(){ $scrolltop.removeClass('car-run');}, 1000);
    return false;
});
$(window).on('scroll', function ()
{ 
    if($(window).scrollTop() >= 200)
    {
        $scrolltop.addClass("show");
        $scrolltop.addClass("car-down");
    }
    else
    {
       $scrolltop.removeClass("show");
       setTimeout(function(){ $scrolltop.removeClass('car-down');}, 300);
    }
});
</script>
</body>
</html>