html-eslint v0.56.0

no-obsolete-tags

This rule disallows the use of obsolete HTML elements in React/JSX code.

How to use

// eslint.config.js (flat config)
import htmlReact from "@html-eslint/eslint-plugin-react";

export default [
  {
    files: ["**/*.jsx", "**/*.tsx"],
    plugins: {
      "@html-eslint/react": htmlReact,
    },
    rules: {
      "@html-eslint/react/no-obsolete-tags": "error",
    },
  },
];

Rule Details

This rule disallows the use of obsolete HTML elements that are no longer part of the HTML5 specification. These elements should be replaced with modern alternatives using CSS or semantic HTML.

Note: This rule only checks lowercase HTML elements (e.g., <center>, <font>). PascalCase React components (e.g., <Center>) and custom elements with hyphens (e.g., <my-font>) are ignored.

Examples

Examples of incorrect code for this rule:

// Layout elements - use CSS instead
<center>Centered content</center>
<marquee>Scrolling text</marquee>

// Font styling elements - use CSS instead
<font color="red">Red text</font>
<big>Large text</big>
<tt>Monospace text</tt>

// Frame elements - use iframe or modern alternatives
<frameset cols="25%,75%">
  <frame src="nav.html" />
  <frame src="content.html" />
</frameset>

// Deprecated elements
<applet code="game.class">Java Applet</applet>
<blink>Blinking text</blink>
<strike>Strikethrough text</strike>
<acronym title="World Wide Web">WWW</acronym>

Examples of correct code for this rule:

// Use CSS for centering
<div style={{ textAlign: 'center' }}>Centered content</div>
<div className="center">Centered content</div>

// Use CSS for font styling
<span style={{ color: 'red' }}>Red text</span>
<span style={{ fontSize: 'larger' }}>Large text</span>
<code>Monospace text</code>

// Use iframe for embedding
<iframe src="content.html" title="Content" />

// Use semantic HTML and CSS
<del>Strikethrough text</del>
<abbr title="World Wide Web">WWW</abbr>

// Custom React components are allowed (PascalCase)
<Center>This is a custom component</Center>
<Font color="red">Custom Font component</Font>

// Custom elements are allowed (with hyphens)
<my-center>Custom element</my-center>
<custom-font>Custom web component</custom-font>

React-specific Notes

  1. Custom components: Components with PascalCase names (e.g., <Center>, <Font>) are treated as React components and ignored by this rule. This allows you to create custom wrapper components with names that match obsolete HTML elements.

  2. Custom elements: Web components with hyphens in their names (e.g., <my-center>, <custom-font>) are also ignored by this rule.

Obsolete Elements

The following elements are considered obsolete according to the HTML5 specification:

Presentational Elements (use CSS instead)

  1. <basefont> - Use CSS font properties
  2. <big> - Use CSS font-size: larger
  3. <blink> - Use CSS animations
  4. <center> - Use CSS text-align: center or flexbox
  5. <font> - Use CSS font properties
  6. <marquee> - Use CSS animations
  7. <nobr> - Use CSS white-space: nowrap
  8. <spacer> - Use CSS margins/padding
  9. <tt> - Use <code>, <kbd>, or CSS font-family: monospace
  10. <strike> - Use <del> or <s> with CSS

Frame Elements

  1. <frame> - Use <iframe> instead
  2. <frameset> - Use modern layout techniques
  3. <noframes> - No longer needed

Other Obsolete Elements

  1. <acronym> - Use <abbr> instead
  2. <applet> - Use <object> or <embed> for plugins
  3. <bgsound> - Use <audio> element
  4. <dir> - Use <ul> instead
  5. <isindex> - Use <input> in a <form>
  6. <keygen> - No longer supported
  7. <listing> - Use <pre> and <code>
  8. <menuitem> - Use <button> or <a> in a menu
  9. <multicol> - Use CSS multi-column layout
  10. <nextid> - No replacement needed
  11. <noembed> - No longer needed
  12. <plaintext> - Use <pre> and escape content
  13. <rb> - Ruby base (use <ruby> structure)
  14. <rtc> - Ruby text container (use <ruby> structure)
  15. <xmp> - Use <pre> and escape content

Modern Alternatives

Centering Content

// ❌ Obsolete
<center>Content</center>

// ✅ Modern CSS
<div style={{ textAlign: 'center' }}>Content</div>
<div className="flex justify-center">Content</div>

Styling Text

// ❌ Obsolete
<font color="red" size="5">Text</font>

// ✅ Modern CSS
<span style={{ color: 'red', fontSize: '1.5rem' }}>Text</span>
<span className="text-red-500 text-xl">Text</span>

Abbreviations

// ❌ Obsolete
<acronym title="HyperText Markup Language">HTML</acronym>

// ✅ Modern
<abbr title="HyperText Markup Language">HTML</abbr>

Strikethrough

// ❌ Obsolete
<strike>Removed text</strike>

// ✅ Modern
<del>Removed text</del>
<s>Incorrect text</s>

Further Reading

  1. HTML Spec - Non-conforming features
  2. MDN - Obsolete and deprecated elements
  3. React DOM Elements