目录
What the figure and figcaption tags do
When to use figure and figcaption
How to use them: Basic syntax
Key points to remember
首页 web前端 html教程 如何使用HTML图和图形标签

如何使用HTML图和图形标签

Aug 03, 2025 pm 12:38 PM

使用figure和figcaption标签能正确地将媒体内容与标题语义化关联,提升可访问性、SEO和结构;1. figure用于包含独立内容如图片、图表或代码片段;2. figcaption为其提供标题,可置于内部首位或末位;3. 适用于有标题的媒体、正文中引用的图表或可移除而不影响文意的内容;4. 使用时需保留图片alt属性,避免仅用于样式布局,允许多媒体组合但每figure仅一个figcaption;5. 默认无视觉样式,需CSS控制外观,但增强HTML语义性。

How to use the HTML figure and figcaption tags

The figure and figcaption HTML tags are useful for semantically grouping images, diagrams, code snippets, or other media with their associated captions. Using them correctly improves accessibility, SEO, and the overall structure of your content.

How to use the HTML figure and figcaption tags

What the figure and figcaption tags do

The <figure></figure> element represents self-contained content that can be moved away from the main content—like illustrations, photos, diagrams, or code examples—without affecting the document’s flow. It’s typically referenced inline but can stand alone.

The <figcaption></figcaption> element provides a caption or legend for the content inside <figure></figure>. It’s optional, but when used, it should be the first or last child of <figure></figure>.

How to use the HTML figure and figcaption tags

Together, they help screen readers and search engines understand the relationship between media and their descriptions.

When to use figure and figcaption

Use these tags when:

How to use the HTML figure and figcaption tags
  • An image, chart, or code block has a caption.
  • The content is referenced from the main text (e.g., “See Figure 1”).
  • The media is self-contained and could be removed without breaking the meaning of the surrounding text.

Common use cases:

  • Photos with descriptive captions
  • Charts or graphs with titles
  • Code snippets with explanations
  • Illustrations in articles

How to use them: Basic syntax

Here’s a simple example with an image:

<figure>
  <img src="/static/imghw/default1.png"  data-src="chart.png"  class="lazy" alt="Sales growth from 2020 to 2023">
  <figcaption>Sales growth over the past three years.</figcaption>
</figure>

And with a code snippet:

<figure>
  <pre class="brush:php;toolbar:false"><code>function hello() {
  console.log("Hello, world!");
}</code>
<figcaption>A simple JavaScript function that prints a message.

You can also place <figcaption> before the content if you want the caption above:

<figure>
  <figcaption>Directory structure of a basic web project.</figcaption>
  <pre class="brush:php;toolbar:false">
project/
├── index.html
├── css/
│   └── style.css
└── js/
    └── main.js
  

Key points to remember

  • Always use alt text on images even inside <figure></figure>. The alt attribute describes the image for accessibility, while <figcaption></figcaption> adds context.
  • Don’t use <figure></figure> just for styling. It’s a semantic element, not a wrapper for floating images.
  • Multiple elements can go in one <figure></figure>, like an image and a chart together with a single caption.
  • Only one <figcaption></figcaption> per <figure></figure>, but it can contain multiple sentences or even paragraphs if needed.

These tags don’t change visual appearance by default—styling is up to CSS—but they make your HTML more meaningful.

Basically, if it looks like a figure in a textbook with a caption underneath (or above), <figure></figure> and <figcaption></figcaption> are probably the right choice.

以上是如何使用HTML图和图形标签的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Laravel 教程
1605
29
PHP教程
1510
276
'`vs.` `在html中 '`vs.` `在html中 Jul 19, 2025 am 12:41 AM

是块级元素,用于划分大块内容区域;是内联元素,适合包裹小段文字或内容片段。具体区别如下:1.独占一行,可设置宽高、内外边距,常用于布局结构如头部、侧边栏等;2.不换行,仅占据内容宽度,用于局部样式控制如变色、加粗等;3.使用场景上,适用于整体区域的排版与结构组织,而用于不影响整体布局的小范围样式调整;4.嵌套时,可包含任何元素,而内部不应嵌套块级元素。

使用HTML`链接rel =' preload”```'' 使用HTML`链接rel =' preload”```'' Jul 19, 2025 am 12:54 AM

linkrel="preload"是一种优化页面加载性能的技术,用于提前加载关键资源。其核心用途在于优先加载对首屏渲染至关重要的资源,如字体、关键CSS/JS和首屏图片。使用时需注意:1.正确设置as属性以指定资源类型;2.避免滥用,防止带宽占用过高;3.确保资源会被实际使用,否则造成请求浪费;4.对跨域资源添加crossorigin属性。错误写法如缺少as属性会导致预加载无效。合理使用可提升页面加载效率,反之则可能适得其反。

初学者的基本HTML标签 初学者的基本HTML标签 Jul 27, 2025 am 03:45 AM

要快速入门HTML,只需掌握几个基础标签即可搭建网页骨架。1.页面结构必备、和,其中是根元素,包含元信息,是内容展示区域。2.标题使用到,级别越高数字越小,正文用标签分段,避免跳级使用。3.链接使用标签并配合href属性,图片使用标签并包含src和alt属性。4.列表分为无序列表和有序列表,每个条目用表示且必须嵌套在列表中。5.初学者不必强记所有标签,边写边查更高效,掌握结构、文本、链接、图片和列表即可制作基础网页。

影子dom概念和HTML集成 影子dom概念和HTML集成 Jul 24, 2025 am 01:39 AM

ShadowDOM是Web组件技术中用于创建隔离DOM子树的技术。1.它允许在普通HTML元素上挂载独立的DOM结构,拥有自己的样式和行为,不与主文档互相影响;2.通过JavaScript创建,例如使用attachShadow方法并设置mode为open;3.结合HTML使用时具备结构清晰、样式隔离和内容投影(slot)三大特点;4.注意事项包括调试复杂、样式作用域控制、性能开销及框架兼容性问题。总之,ShadowDOM提供了原生封装能力,适用于构建可复用且不污染全局的UI组件。

您可以在另一个标签中放置一个标签吗? 您可以在另一个标签中放置一个标签吗? Jul 27, 2025 am 04:15 AM

❌Youcannotnesttagsinsideanothertagbecauseit’sinvalidHTML;browsersautomaticallyclosethefirstbeforeopeningthenext,resultinginseparateparagraphs.✅Instead,useinlineelementslike,,orforstylingwithinaparagraph,orblockcontainerslikeortogroupmultipleparagraph

使用html`下载属性的链接属性 使用html`下载属性的链接属性 Jul 17, 2025 am 03:57 AM

TheHTMLdownloadattributeallowsuserstodownloadfilesdirectlyfromalinkbyusingthetag.Toimplementit,adddownloadtotheanchortag,suchasDownloadPDF,orspecifyacustomfilenamelikeDownloadasmy-document.pdf.1.Itworksbestwithsame-originURLsandcommonfiletypeslikePDF

html'样式”标签:内联与内部CSS html'样式”标签:内联与内部CSS Jul 26, 2025 am 07:23 AM

样式放置方式需根据场景选择。1.Inline适合单元素临时修改或JS动态控制,如按钮颜色随操作变化;2.内部CSS适合页面少、结构简单项目,便于集中管理样式,如登录页基础样式设置;3.优先考虑复用性、维护性及性能,大项目拆分外链CSS文件更优。

如何在HTML中嵌入YouTube视频 如何在HTML中嵌入YouTube视频 Jul 16, 2025 am 04:43 AM

要在网页中嵌入YouTube视频,可直接复制YouTube提供的嵌入代码并粘贴到HTML页面中;1.打开目标视频页面并确认正确视频链接;2.点击“分享”→“嵌入”,复制生成的iframe代码;3.或手动创建iframe标签并设置src为https://www.youtube.com/embed/视频ID;4.推荐使用响应式宽度和添加allowfullscreen属性;5.进阶建议包括使用容器实现16:9比例、延迟加载以提升性能及注意隐私政策提示。

See all articles