├── .editorconfig ├── .gitattributes ├── .github ├── security.md └── workflows │ ├── main.yml │ └── update.yml ├── .gitignore ├── .npmrc ├── html-tags-void.d.ts ├── html-tags-void.json ├── html-tags.d.ts ├── html-tags.json ├── index.d.ts ├── index.js ├── license ├── package.json ├── readme.md ├── scripts └── build.js └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 24 14 | - 22 15 | - 20 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-node@v4 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - run: npm install 22 | - run: npm test 23 | -------------------------------------------------------------------------------- /.github/workflows/update.yml: -------------------------------------------------------------------------------- 1 | name: Update 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | # “At 00:00 on day-of-month 1.” https://crontab.guru/#0_0_1_*_* 7 | - cron: "0 0 1 * *" 8 | 9 | jobs: 10 | update: 11 | if: github.event_name != 'schedule' || github.repository == 'sindresorhus/html-tags' 12 | runs-on: ubuntu-latest 13 | permissions: 14 | pull-requests: write 15 | contents: write 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-node@v4 19 | - run: npm install 20 | - run: npm run build 21 | - uses: peter-evans/create-pull-request@v7 22 | with: 23 | commit-message: Update 24 | branch: automated-update 25 | branch-suffix: timestamp 26 | title: Update 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | .cache 4 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /html-tags-void.d.ts: -------------------------------------------------------------------------------- 1 | export type VoidHtmlTags = 2 | | 'area' 3 | | 'base' 4 | | 'br' 5 | | 'col' 6 | | 'embed' 7 | | 'hr' 8 | | 'img' 9 | | 'input' 10 | | 'link' 11 | | 'meta' 12 | | 'source' 13 | | 'track' 14 | | 'wbr'; 15 | -------------------------------------------------------------------------------- /html-tags-void.json: -------------------------------------------------------------------------------- 1 | [ 2 | "area", 3 | "base", 4 | "br", 5 | "col", 6 | "embed", 7 | "hr", 8 | "img", 9 | "input", 10 | "link", 11 | "meta", 12 | "source", 13 | "track", 14 | "wbr" 15 | ] 16 | -------------------------------------------------------------------------------- /html-tags.d.ts: -------------------------------------------------------------------------------- 1 | export type HtmlTags = 2 | | 'a' 3 | | 'abbr' 4 | | 'address' 5 | | 'area' 6 | | 'article' 7 | | 'aside' 8 | | 'audio' 9 | | 'b' 10 | | 'base' 11 | | 'bdi' 12 | | 'bdo' 13 | | 'blockquote' 14 | | 'body' 15 | | 'br' 16 | | 'button' 17 | | 'canvas' 18 | | 'caption' 19 | | 'cite' 20 | | 'code' 21 | | 'col' 22 | | 'colgroup' 23 | | 'data' 24 | | 'datalist' 25 | | 'dd' 26 | | 'del' 27 | | 'details' 28 | | 'dfn' 29 | | 'dialog' 30 | | 'div' 31 | | 'dl' 32 | | 'dt' 33 | | 'em' 34 | | 'embed' 35 | | 'fieldset' 36 | | 'figcaption' 37 | | 'figure' 38 | | 'footer' 39 | | 'form' 40 | | 'h1' 41 | | 'h2' 42 | | 'h3' 43 | | 'h4' 44 | | 'h5' 45 | | 'h6' 46 | | 'head' 47 | | 'header' 48 | | 'hgroup' 49 | | 'hr' 50 | | 'html' 51 | | 'i' 52 | | 'iframe' 53 | | 'img' 54 | | 'input' 55 | | 'ins' 56 | | 'kbd' 57 | | 'label' 58 | | 'legend' 59 | | 'li' 60 | | 'link' 61 | | 'main' 62 | | 'map' 63 | | 'mark' 64 | | 'math' 65 | | 'menu' 66 | | 'meta' 67 | | 'meter' 68 | | 'nav' 69 | | 'noscript' 70 | | 'object' 71 | | 'ol' 72 | | 'optgroup' 73 | | 'option' 74 | | 'output' 75 | | 'p' 76 | | 'picture' 77 | | 'pre' 78 | | 'progress' 79 | | 'q' 80 | | 'rp' 81 | | 'rt' 82 | | 'ruby' 83 | | 's' 84 | | 'samp' 85 | | 'script' 86 | | 'search' 87 | | 'section' 88 | | 'select' 89 | | 'slot' 90 | | 'small' 91 | | 'source' 92 | | 'span' 93 | | 'strong' 94 | | 'style' 95 | | 'sub' 96 | | 'summary' 97 | | 'sup' 98 | | 'svg' 99 | | 'table' 100 | | 'tbody' 101 | | 'td' 102 | | 'template' 103 | | 'textarea' 104 | | 'tfoot' 105 | | 'th' 106 | | 'thead' 107 | | 'time' 108 | | 'title' 109 | | 'tr' 110 | | 'track' 111 | | 'u' 112 | | 'ul' 113 | | 'var' 114 | | 'video' 115 | | 'wbr'; 116 | -------------------------------------------------------------------------------- /html-tags.json: -------------------------------------------------------------------------------- 1 | [ 2 | "a", 3 | "abbr", 4 | "address", 5 | "area", 6 | "article", 7 | "aside", 8 | "audio", 9 | "b", 10 | "base", 11 | "bdi", 12 | "bdo", 13 | "blockquote", 14 | "body", 15 | "br", 16 | "button", 17 | "canvas", 18 | "caption", 19 | "cite", 20 | "code", 21 | "col", 22 | "colgroup", 23 | "data", 24 | "datalist", 25 | "dd", 26 | "del", 27 | "details", 28 | "dfn", 29 | "dialog", 30 | "div", 31 | "dl", 32 | "dt", 33 | "em", 34 | "embed", 35 | "fieldset", 36 | "figcaption", 37 | "figure", 38 | "footer", 39 | "form", 40 | "h1", 41 | "h2", 42 | "h3", 43 | "h4", 44 | "h5", 45 | "h6", 46 | "head", 47 | "header", 48 | "hgroup", 49 | "hr", 50 | "html", 51 | "i", 52 | "iframe", 53 | "img", 54 | "input", 55 | "ins", 56 | "kbd", 57 | "label", 58 | "legend", 59 | "li", 60 | "link", 61 | "main", 62 | "map", 63 | "mark", 64 | "math", 65 | "menu", 66 | "meta", 67 | "meter", 68 | "nav", 69 | "noscript", 70 | "object", 71 | "ol", 72 | "optgroup", 73 | "option", 74 | "output", 75 | "p", 76 | "picture", 77 | "pre", 78 | "progress", 79 | "q", 80 | "rp", 81 | "rt", 82 | "ruby", 83 | "s", 84 | "samp", 85 | "script", 86 | "search", 87 | "section", 88 | "select", 89 | "slot", 90 | "small", 91 | "source", 92 | "span", 93 | "strong", 94 | "style", 95 | "sub", 96 | "summary", 97 | "sup", 98 | "svg", 99 | "table", 100 | "tbody", 101 | "td", 102 | "template", 103 | "textarea", 104 | "tfoot", 105 | "th", 106 | "thead", 107 | "time", 108 | "title", 109 | "tr", 110 | "track", 111 | "u", 112 | "ul", 113 | "var", 114 | "video", 115 | "wbr" 116 | ] 117 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | import type {HtmlTags} from './html-tags.js'; 2 | import type {VoidHtmlTags} from './html-tags-void.js'; 3 | 4 | /** 5 | List of standard HTML tags. 6 | 7 | @example 8 | ``` 9 | import htmlTags from 'html-tags'; 10 | 11 | console.log(htmlTags); 12 | //=> ['a', 'abbr', 'acronym', …] 13 | ``` 14 | */ 15 | declare const htmlTags: readonly HtmlTags[]; 16 | 17 | export default htmlTags; 18 | 19 | /** 20 | List of standard, self-closing HTML tags. 21 | 22 | @example 23 | ``` 24 | import {voidHtmlTags} from 'html-tags'; 25 | 26 | console.log(voidHtmlTags); 27 | //=> ['area', 'base', 'br', …] 28 | ``` 29 | */ 30 | export const voidHtmlTags: readonly VoidHtmlTags[]; 31 | 32 | export type {HtmlTags} from './html-tags.js'; 33 | export type {VoidHtmlTags} from './html-tags-void.js'; 34 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | export {default} from './html-tags.json' with {type: 'json'}; 3 | export {default as voidHtmlTags} from './html-tags-void.json' with {type: 'json'}; 4 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "html-tags", 3 | "version": "5.0.0", 4 | "description": "List of standard HTML tags", 5 | "license": "MIT", 6 | "repository": "sindresorhus/html-tags", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": { 15 | "types": "./index.d.ts", 16 | "default": "./index.js" 17 | }, 18 | "sideEffects": false, 19 | "engines": { 20 | "node": ">=20.10" 21 | }, 22 | "scripts": { 23 | "test": "xo && ava", 24 | "build": "node scripts/build.js" 25 | }, 26 | "files": [ 27 | "index.js", 28 | "html-tags.json", 29 | "html-tags-void.json", 30 | "index.d.ts", 31 | "html-tags.d.ts", 32 | "html-tags-void.d.ts" 33 | ], 34 | "keywords": [ 35 | "html", 36 | "html5", 37 | "tags", 38 | "elements", 39 | "list", 40 | "whatwg", 41 | "w3c", 42 | "void", 43 | "self-closing" 44 | ], 45 | "devDependencies": { 46 | "ava": "^6.3.0", 47 | "cheerio": "^1.0.0", 48 | "xo": "^0.61.0-2" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # html-tags 2 | 3 | > List of standard HTML tags 4 | 5 | It's just a couple of JSON files that can be used in any environment. 6 | 7 | It intentionally leaves out [obsolete tags](https://html.spec.whatwg.org/multipage/obsolete.html#non-conforming-features). 8 | 9 | ## Install 10 | 11 | ```sh 12 | npm install html-tags 13 | ``` 14 | 15 | ## Usage 16 | 17 | ```js 18 | import htmlTags from 'html-tags'; 19 | 20 | console.log(htmlTags); 21 | //=> ['a', 'abbr', 'acronym', …] 22 | ``` 23 | 24 | And void (self-closing) tags: 25 | 26 | ```js 27 | import {voidHtmlTags} from 'html-tags'; 28 | 29 | console.log(voidHtmlTags); 30 | //=> ['area', 'base', 'br', …] 31 | ``` 32 | 33 | ## Contribute 34 | 35 | Make sure to update types in `index.d.ts` when changing HTML elements. 36 | -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | import fs from 'node:fs/promises'; 2 | import * as cheerio from 'cheerio'; 3 | 4 | const CACHE_DIRECTORY = new URL('../.cache/', import.meta.url); 5 | const CACHE_DURATION = 10 * 60 * 60 * 1000; // 10 hours 6 | 7 | const getHtml = async url => { 8 | const cacheFile = new URL(url.split('/').at(-1), CACHE_DIRECTORY); 9 | 10 | let stat; 11 | 12 | try { 13 | stat = await fs.stat(cacheFile); 14 | } catch {} 15 | 16 | if (stat) { 17 | if ((Date.now() - stat.mtimeMs) < CACHE_DURATION) { 18 | return fs.readFile(cacheFile, 'utf8'); 19 | } 20 | 21 | await fs.rm(cacheFile); 22 | } 23 | 24 | const response = await fetch(url); 25 | 26 | if (!response.ok) { 27 | throw new Error('Request failed.'); 28 | } 29 | 30 | const text = await response.text(); 31 | 32 | await fs.mkdir(CACHE_DIRECTORY, {recursive: true}); 33 | await fs.writeFile(cacheFile, text); 34 | 35 | return text; 36 | }; 37 | 38 | async function getTags() { 39 | const html = await getHtml('https://html.spec.whatwg.org/multipage/indices.html'); 40 | const $ = cheerio.load(html); 41 | const table = $('#elements-3 ~ table')[0]; 42 | 43 | return Array.from( 44 | $('th:first-child code', table), 45 | element => $(element).text().trim(), 46 | ).sort(); 47 | } 48 | 49 | async function getVoidTags() { 50 | const html = await getHtml('https://html.spec.whatwg.org/multipage/syntax.html'); 51 | const $ = cheerio.load(html); 52 | 53 | return Array.from( 54 | $('dt:has(#void-elements) + dd > code > a'), 55 | element => $(element).text().trim(), 56 | ).sort(); 57 | } 58 | 59 | await Promise.all([ 60 | {getData: getTags, basename: 'html-tags', typeName: 'HtmlTags'}, 61 | {getData: getVoidTags, basename: 'html-tags-void', typeName: 'VoidHtmlTags'}, 62 | ].map(async ({getData, basename, typeName}) => { 63 | const tags = await getData(); 64 | 65 | await fs.writeFile( 66 | new URL(`../${basename}.json`, import.meta.url), 67 | JSON.stringify(tags, undefined, '\t') + '\n', 68 | ); 69 | await fs.writeFile( 70 | new URL(`../${basename}.d.ts`, import.meta.url), 71 | `export type ${typeName} =\n${tags.map(tag => `\t| '${tag}'`).join('\n')};\n`, 72 | ); 73 | })); 74 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import htmlTags, {voidHtmlTags} from './index.js'; 3 | 4 | test('htmlTags is an array of HTML tags', t => { 5 | t.true(Array.isArray(htmlTags)); 6 | t.true(htmlTags.length > 10 && htmlTags.length < 1000); 7 | }); 8 | 9 | test('voidHtmlTags is an array of void HTML tags', t => { 10 | t.true(Array.isArray(voidHtmlTags)); 11 | t.true(voidHtmlTags.length > 10 && voidHtmlTags.length < 1000); 12 | }); 13 | --------------------------------------------------------------------------------