npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

validation-output

v0.1.5

Published

Provides a way to show and style client side validation errors how you wish.

Downloads

38

Readme

Validation Output

NPM Version

A web component for custom client-side form validation. Replaces the browser's default validation UI with your own styled messages. Gives you control over how validation feedback is displayed to users and keeps it consistent across your application.

View live demo

Installation

Package manager

Install using your package manager of choice:

npm install validation-output

Then import the component in your project:

import 'validation-output';

CDN

You can also load the component via CDN:

<script type="module" src="https://cdn.jsdelivr.net/npm/validation-output@latest/validation-output.min.js"></script>

Usage

Basic Client-Side Validation

Use the for attribute to associate the validation output with an input element. This allows you to control the placement and styling of validation messages.

<input type="email" id="email" />
<validation-output for="email"></validation-output>

Custom Validation Messages

Display custom messages for specific validation errors using a <template> with data-validity attributes. The attribute value must match a property from the ValidityState API.

<template id="validation-messages">
    <template data-validity="typeMismatch">
        This is not looking right
    </template>
    <template data-validity="valueMissing">
        I expect an <b>email</b>, <i>darling!</i>
    </template>
</template>

<input type="email" id="email" required />
<validation-output for="email" template="validation-messages"></validation-output>
<input type="number" id="number" required />
<validation-output for="number" template="validation-messages"></validation-output>

Server-Side Validation

Add text content to the <validation-output> element to display server-side validation errors:

<input type="email" id="email" value="known@email" />
<validation-output for="email">
    Invalid credentials. Please try again.
</validation-output>

<input type="text" id="persistent" value="rejected-value" />
<validation-output for="persistent" persistent>
    This error will be show again if the value is changed back to the rejected value
</validation-output>

When the user modifies the input field, the server-side message is hidden. If the persistent attribute is set and the user changes the value back to the rejected value, the message will be shown again.

Note: When displaying server-side validation errors, the input element won't have the :user-invalid pseudo-class applied. To style server-validated inputs, you can use the data-server-invalid="true" attribute selector instead. This attribute is automatically removed once the user modifies the input, allowing you to switch to :user-invalid styling.

Styling

Style the validation output using standard CSS. You can use the :user-invalid, :invalid on the input field for styling.

On the validation-output element, you can use the :state(has-error) selector to style the validation output when it contains an error.

input:user-invalid  {
    border: 1px solid darkred;
}
validation-output {
    color: darkred;
    display: none;
}
validation-output:state(has-error) {
    display: block;
}

API

Attributes

| Attribute | Required | Description | |--------------|----------|-----------------------------------------------------------------------------------| | for | Yes | ID of the input element to validate | | template | No | ID of the template containing custom validation messages | | persistent | No | Show the server validation error again if the value reverts to the rejected value |