HTML <figcaption> class Attribute

The class attribute on a <figcaption> tag assigns one or more classnames to the figcaption element. Classes are used to style elements. Classnames are defined in a stylesheet or in a local <style> element.

Example

#

A class attribute styling a <figcaption> element.

A Beautiful Oil Painting
<style>
  .fig {color:teal; font-style:italic; font-size:20px; }
</style>

<figure>
  <img src="/img/html/sangiorgio.jpg">
  <figcaption class="fig">A Beautiful Oil Painting</figcaption>
</figure>

Using class

The class attribute assigns one or more classnames to the <figcaption> tag.

Multiple classnames are separated by a space.

Classes (i.e. classnames) are used for styling the figcaption element.

JavaScript uses classes to access one or more elements by classname.

Tip:  class is a global attribute that can be applied to any HTML element.


Syntax

<figcaption class="classnames">

Values

#

Value Description
classnames One or more space-separated class names.

More Examples

A class attribute styling a <figcaption> element.
Clicking the button toggles a classname that adds an underline.

A Beautiful Oil Painting

<style>
  .figcaption {color:teal; font-style:italic; font-size:20px; }
  .fc-underline { text-decoration: underline; }
</style>

<figure>
  <img src="/img/html/sangiorgio.jpg">
  <figcaption id="myfigcaption" class="figcaption">
    A Beautiful Oil Painting
  </figcaption>
</figure>

<br/>
<button onclick="toggle();">Toggle class</button>

<script>
  let toggle = () => {
    let element = document.getElementById("myfigcaption");
    element.classList.toggle("fc-underline");
  }
</script>

Code explanation

Three CSS classes are defined in the <style> element.

The class attribute in <figcaption> assigns two from those.

Repeatedly clicking the button toggles the third class, changing the text decoration of the <figcaption>.


Browser support

Here is when class support started for each browser:

Chrome
6.0 Sep 2010
Firefox
4.0 Mar 2011
IE/Edge
9.0 Mar 2011
Opera
11.1 Mar 2011
Safari
5.0 Jun 2010

You may also like

 Back to <figcaption>
Guides