tag:normalise Hook · Unhead

[Unhead Home](https://unhead.unjs.io/ "Home")

- [Docs](https://unhead.unjs.io/docs/vue/head/guides/get-started/overview)
- [Tools](https://unhead.unjs.io/tools)
- [Learn](https://unhead.unjs.io/learn/guides/what-is-capo)

[Releases](https://unhead.unjs.io/releases)

Search…```k`` /`

[Unhead on GitHub](https://github.com/unjs/unhead)

[User Guides](https://unhead.unjs.io/docs/vue/head/guides/get-started/overview)

[API](https://unhead.unjs.io/docs/vue/head/api/get-started/overview)

[Releases](https://unhead.unjs.io/docs/vue/releases/v3)

Vue

- [Switch to Vue](https://unhead.unjs.io/docs/vue/head/api/hooks/tag-normalise)
- [Switch to TypeScript](https://unhead.unjs.io/docs/typescript/head/api/hooks/tag-normalise)
- [Switch to React](https://unhead.unjs.io/docs/react/head/api/hooks/tag-normalise)
- [Switch to Svelte](https://unhead.unjs.io/docs/svelte/head/api/hooks/tag-normalise)
- [Switch to Solid.js](https://unhead.unjs.io/docs/solid-js/head/api/hooks/tag-normalise)
- [Switch to Angular](https://unhead.unjs.io/docs/angular/head/api/hooks/tag-normalise)
- [Switch to Nuxt](https://unhead.unjs.io/docs/nuxt/head/api/hooks/tag-normalise)

v3 (stable)

Head

- [Discord Support](https://discord.com/invite/275MBUBvgP)
- [Vue Playground](https://stackblitz.com/edit/github-1ftqrmwn)

- Get Started
  - [Overview](https://unhead.unjs.io/docs/vue/head/api/get-started/overview)
- Composables
  - [`useHead()`](https://unhead.unjs.io/docs/vue/head/api/composables/use-head)
  - [`useHeadSafe()`](https://unhead.unjs.io/docs/vue/head/api/composables/use-head-safe)
  - [`useSeoMeta()`](https://unhead.unjs.io/docs/vue/head/api/composables/use-seo-meta)
  - [`useScript()`](https://unhead.unjs.io/docs/vue/head/api/composables/use-script)
- Hooks
  - [entries:updated](https://unhead.unjs.io/docs/vue/head/api/hooks/entries-updated)
  - [entries:resolve](https://unhead.unjs.io/docs/vue/head/api/hooks/entries-resolve)
  - [entries:normalize](https://unhead.unjs.io/docs/vue/head/api/hooks/entries-normalize)
  - [tag:normalise](https://unhead.unjs.io/docs/vue/head/api/hooks/tag-normalise)
  - [tags:beforeResolve](https://unhead.unjs.io/docs/vue/head/api/hooks/tags-before-resolve)
  - [tags:resolve](https://unhead.unjs.io/docs/vue/head/api/hooks/tags-resolve)
  - [tags:afterResolve](https://unhead.unjs.io/docs/vue/head/api/hooks/tags-after-resolve)
  - [dom:beforeRender](https://unhead.unjs.io/docs/vue/head/api/hooks/dom-before-render)
  - [ssr:beforeRender](https://unhead.unjs.io/docs/vue/head/api/hooks/ssr-before-render)
  - [ssr:render](https://unhead.unjs.io/docs/vue/head/api/hooks/ssr-render)
  - [ssr:rendered](https://unhead.unjs.io/docs/vue/head/api/hooks/ssr-rendered)
  - [script:updated](https://unhead.unjs.io/docs/vue/head/api/hooks/script-updated)
- [Plugins](https://unhead.unjs.io/docs/head/api/plugins)

Hooks

# tag:normalise Hook

[Copy for LLMs](https://raw.githubusercontent.com/unjs/unhead/refs/heads/main/docs/head/7.api/hooks/05.tag-normalise.md)

Last updated Jan 19, 2026 by [Harlan Wilton](https://github.com/harlan-zw) in [docs: sync](https://github.com/unjs/unhead/commit/d2f86454774aa60706628b46a850653e1e4d56d9).

On this page

- [Lifecycle Position](#lifecycle-position)
- [Hook Signature](#hook-signature)
- [Usage Example](#usage-example)
- [Use Cases](#use-cases)

The `tag:normalise` hook is called for each individual tag during the normalization process. This hook gives you access to a single tag, its parent entry, and resolved options, allowing you to apply fine-grained modifications to specific tags.

## [Lifecycle Position](#lifecycle-position)

This hook runs after [`entries:normalize`](https://unhead.unjs.io/docs/head/api/hooks/entries-normalize) and before [`tags:beforeResolve`](https://unhead.unjs.io/docs/head/api/hooks/tags-before-resolve).

## [Hook Signature](#hook-signature)

```
export interface Hook {
  'tag:normalise': (ctx: {
    tag: HeadTag
    entry: HeadEntry<any>
    resolvedOptions: CreateClientHeadOptions
  }) => HookResult
}
```

### [Parameters](#parameters)

| Name | Type | Description |
| --- | --- | --- |
| `ctx` | Object | Context object containing the tag information |
| `ctx.tag` | `HeadTag` | The head tag being normalized |
| `ctx.entry` | `HeadEntry<any>` | The entry that generated this tag |
| `ctx.resolvedOptions` | `CreateClientHeadOptions` | The resolved options for the head instance |

### [Returns](#returns)

`HookResult` which is either `void` or `Promise<void>`

## [Usage Example](#usage-example)

```
import { createHead } from '@unhead/vue'

const head = createHead({
  hooks: {
    'tag:normalise': (ctx) => {
      const { tag, entry } = ctx

      // Apply specific modifications based on tag type
      if (tag.tag === 'link' && tag.props.rel === 'stylesheet') {
        // Add integrity check to all stylesheets
        tag.props.crossorigin = 'anonymous'
      }

      // Add source information for debugging
      tag._source = entry.options.source || 'unknown'
    }
  }
})
```

## [Use Cases](#use-cases)

### [Fine-tuning Specific Tag Types](#fine-tuning-specific-tag-types)

This hook is ideal for applying modifications to specific types of tags:

```
import { defineHeadPlugin } from '@unhead/vue'

export const scriptSecurityPlugin = defineHeadPlugin({
  hooks: {
    'tag:normalise': (ctx) => {
      const { tag } = ctx

      // Add security attributes to all script tags
      if (tag.tag === 'script' && tag.props.src) {
        // Apply Content Security Policy attributes
        tag.props.crossorigin = 'anonymous'

        // Add nonce for CSP if available
        if (globalThis.SCRIPT_NONCE) {
          tag.props.nonce = globalThis.SCRIPT_NONCE
        }
      }
    }
  }
})
```

### [Tag Transformation Based on Environment](#tag-transformation-based-on-environment)

Transform tags differently based on the environment:

```
import { defineHeadPlugin } from '@unhead/vue'

export const environmentSpecificPlugin = defineHeadPlugin({
  hooks: {
    'tag:normalise': (ctx) => {
      const { tag, resolvedOptions } = ctx
      const isDevelopment = process.env.NODE_ENV === 'development'

      // Handle environment-specific transformations
      if (tag.tag === 'meta' && tag.props.name === 'robots') {
        // Prevent indexing in development or staging environments
        if (isDevelopment || resolvedOptions.environment === 'staging') {
          tag.props.content = 'noindex, nofollow'
        }
      }

      // Add debug information in development
      if (isDevelopment && tag.tag !== 'comment') {
        tag.props['data-dev-info'] = \`Entry: ${ctx.entry._i}\`
      }
    }
  }
})
```

### [Custom Attribute Processing](#custom-attribute-processing)

Process custom attributes that need special handling:

```
import { defineHeadPlugin } from '@unhead/vue'

export const dataAttributeProcessingPlugin = defineHeadPlugin({
  hooks: {
    'tag:normalise': (ctx) => {
      const { tag } = ctx

      // Process data attributes with special formatting
      Object.keys(tag.props).forEach((prop) => {
        if (prop.startsWith('data-')) {
          // Convert camelCase values to kebab-case for data attributes
          if (typeof tag.props[prop] === 'string'
            && tag.props[prop].includes('_')) {
            tag.props[prop] = tag.props[prop]
              .replace(/_([a-z])/g, (_, char) => \`-${char.toLowerCase()}\`)
          }

          // Convert objects to JSON strings for data attributes
          if (typeof tag.props[prop] === 'object' && tag.props[prop] !== null) {
            tag.props[prop] = JSON.stringify(tag.props[prop])
          }
        }
      })
    }
  }
})
```

[Edit this page](https://github.com/unjs/unhead/edit/main/docs/head/7.api/hooks/05.tag-normalise.md)

[Markdown For LLMs](https://raw.githubusercontent.com/unjs/unhead/refs/heads/main/docs/head/7.api/hooks/05.tag-normalise.md)

Did this page help you?

[entries:normalize Hook for normalizing individual head entries. Add entry-specific attributes, conditional modifications, and template processing.](https://unhead.unjs.io/docs/head/api/hooks/entries-normalize) [tags:beforeResolve Hook called before tag resolution. Pre-process tags, add global meta tags, and filter based on environment conditions.](https://unhead.unjs.io/docs/head/api/hooks/tags-before-resolve)

On this page

- [Lifecycle Position](#lifecycle-position)
- [Hook Signature](#hook-signature)
- [Usage Example](#usage-example)
- [Use Cases](#use-cases)

[GitHub](https://github.com/unjs/unhead) [ Discord](https://discord.com/invite/275MBUBvgP)

[ /llms.txt](https://unhead.unjs.io/llms.txt)

[Part of the UnJS ecosystem](https://unjs.io/)

### Head Management

- [Getting Started](https://unhead.unjs.io/docs/vue/head/guides/get-started/overview)
- [useHead](https://unhead.unjs.io/docs/vue/head/api/composables/use-head)
- [useSeoMeta](https://unhead.unjs.io/docs/vue/head/api/composables/use-seo-meta)
- [useHeadSafe](https://unhead.unjs.io/docs/vue/head/api/composables/use-head-safe)
- [useScript](https://unhead.unjs.io/docs/vue/head/api/composables/use-script)

### Schema.org

- [Getting Started](https://unhead.unjs.io/docs/vue/schema-org/guides/get-started/overview)
- [useSchemaOrg](https://unhead.unjs.io/docs/vue/schema-org/api/composables/use-schema-org)
- [Nodes](https://unhead.unjs.io/docs/vue/schema-org/guides/core-concepts/nodes)
- [Recipes](https://unhead.unjs.io/docs/vue/schema-org/guides/recipes/identity)

### Guides

- [Titles](https://unhead.unjs.io/docs/vue/head/guides/core-concepts/titles)
- [Streaming SSR](https://unhead.unjs.io/docs/vue/head/guides/core-concepts/streaming)
- [DOM Events](https://unhead.unjs.io/docs/vue/head/guides/core-concepts/dom-event-handling)
- [Plugins](https://unhead.unjs.io/docs/vue/head/guides/plugins/template-params)

### Tools

- [Meta Tag Generator](https://unhead.unjs.io/tools/meta-tag-generator)
- [OG Image Generator](https://unhead.unjs.io/tools/og-image-generator)
- [Schema.org Generator](https://unhead.unjs.io/tools/schema-generator)
- [Capo.js Analyzer](https://unhead.unjs.io/tools/capo-analyzer)

### Articles

- [What is Capo.js?](https://unhead.unjs.io/learn/guides/what-is-capo)

### Research

- [State of <head> in 2026](https://unhead.unjs.io/learn/research/state-of-head-2026)
- [Streaming Head Performance](https://unhead.unjs.io/learn/research/streaming-head-performance)
- [Capo.js Performance Research](https://unhead.unjs.io/learn/research/capo-performance-research)

Copyright © 2025-2026 Harlan Wilton - [MIT License](https://github.com/unjs/unhead/blob/main/license)