Registration Form in HTML

This registration form HTML CSS JavaScript tutorial shows you how to build a two-panel sign up page with an accent panel on the left and a clean form on the right. The form includes name, email, and password fields, a show and hide password button, a consent checkbox, and a full width submit button. I also cover accessibility basics like labels, aria-describedby, a visually hidden label, and :focus-visible styles. The CSS uses nesting and clamp(), so the layout scales smoothly on any screen.

Final preview:

Lemon.

A little more clarity. Every day.

Good work
starts here.

A considered space to organize your work, find your focus, and move forward.

Free to get started. Room to grow.

Get Started

Create your account

A fresh space for your next chapter.

• At least 8 characters.

Skip to view source code


Steps for Registration Form in HTML:

1. Set Up the Section and Base Styles

Link the Inter font from Google Font in the head.

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap" rel="stylesheet">

Let’s start with a section element with the class registration-section. Inside it, I am adding a .registration-container div, and inside that, a .registration-grid div.

<header class="navbar">
    <div class="navbar-container"></div>
</header>

Then reset the margins and define the colors as CSS variables on :root. Next, give the section a muted background, and use clamp() on the padding.

* {
    margin: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: hsla(214, 54%, 39%, 1);
    --color-text-primary: hsla(217, 36%, 18%, 1);
    --color-text-secondary: hsla(215, 22%, 34%, 1);
    --color-heading: hsla(214, 51%, 18%, 1);
    --color-border: hsla(214, 21%, 87%, 1);
    --color-surface: hsla(0, 0%, 100%, 1);
    --color-surface-muted: hsla(210, 22%, 96%, 1);
    --color-surface-accent: hsla(214, 50%, 95%, 1);
}

body {
    font-family: "Inter", sans-serif;
    color: var(--color-text-secondary);
}

.registration-section {
    padding: clamp(1rem, calc(1rem + 1.67vw), 2.5rem);
    background-color: var(--color-surface-muted);
}

Note:
clamp(). It takes three values: a minimum, an ideal value, and a maximum. The browser picks the ideal value, but never goes below the minimum or above the maximum. So the padding grows with the screen, and it stays between 1rem and 2.5rem.
CSS variables. Defining colors once on :root means you can change the whole theme from one place. You read a variable with var(–name)

Next, center the container with the margin inline property set to auto and a max width. Add a border and a border radius. Then set the overflow property to hidden, so the two panels stay clipped inside the rounded corners. Inside it, use a two-column grid, and collapse to one column on small screens. Add this nested inside .registration-section.

.registration-container {
    border: 1px solid var(--color-border);
    border-radius: .75rem;
    max-width: 85rem;
    margin-inline: auto;
    overflow: hidden;

    .registration-grid {
        display: grid;
        grid-template-columns: 0.852fr 1fr;

        @media (width < 769px) {
            grid-template-columns: 1fr;
        }
    }
}

2. Build the Left Panel

Now add the .registration-content-wrapper inside the grid. It holds the logo link, a small eyebrow label, the heading, a description, and a small reassurance row with a check icon.

<div class="registration-content-wrapper">
    <a href="#">Lemon.</a>
    <p class="eyebrow">A little more clarity. Every day.</p>
    <h2>Good work<br> starts here.</h2>
    <p class="registration-description">A considered space to organize your work, find your focus, and move forward.</p>
    <div>
        <svg aria-hidden="true" focusable="false" width="100%" height="100%" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <rect x="0.5" y="0.5" width="23" height="23" rx="11.5" stroke="#B7C9DF" />
            <path d="M6.16666 12L9.49999 15.3333L17.8333 7" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round" stroke="#355577" />
        </svg>
        <p>Free to get started. Room to grow.</p>
    </div>
</div>

Give the panel an accent background color, and add a decorative shape image at the bottom right. Set a minimum height, so the panel stays tall even with little content. Add this inside .registration-grid.

.registration-content-wrapper {
    padding: clamp(1rem, calc(1rem + 3.33vw), 4rem);
    background: var(--color-surface-accent) url('bg-shape.png') bottom right no-repeat;
    min-height: 46rem;
    background-size: 85%;

    @media (width < 1025px) {
        min-height: 35rem;
    }
}

Note:
accessibility (a11y) for icons. The check icon is decorative, since the text beside it says everything. So I added aria-hidden=”true” to hide it from screen readers, and focusable=”false” so old browsers do not tab into the SVG.

Output:

Lemon.

A little more clarity. Every day.

Good work
starts here.

A considered space to organize your work, find your focus, and move forward.

Free to get started. Room to grow.

3. Style the Eyebrow and the Left Panel Text

The eyebrow label is used on both panels, so style it once on .registration-grid. Add this inside .registration-grid.

.eyebrow {
    font-weight: 600;
    font-size: .75rem;
    line-height: 1.33;
    letter-spacing: 0.17em;
    text-transform: uppercase;
}

Then style the logo link without an underline, and give it a tight letter spacing. Add a large top margin to the eyebrow, so there is a gap under the logo. Use clamp() on the heading font size, and add a block margin to space it away from the neighbors. Add this inside .registration-content-wrapper.

a {
    text-decoration: none;
    color: inherit;
    font-weight: 600;
    font-size: 1.625rem;
    line-height: 1.5;
    letter-spacing: -0.0385em;
}

.eyebrow {
    margin-block-start: clamp(3.5rem, calc(1rem + 5.56vw), 6rem);
}

h2 {
    margin-block: 1.25rem;
    font-weight: 500;
    font-size: clamp(2.75rem, calc(1rem + 2.78vw), 3.5rem);
    line-height: 1.125;
    letter-spacing: -0.0385em;
    color: var(--color-heading);
}

.registration-description {
    font-size: 1rem;
    line-height: 1.75;
    max-width: 22rem;
}

Use flexbox with the align items property set to center, so the check icon and the text sit on one line. Fix the icon size, since the SVG has a width of 100% in the markup. Add this inside .registration-content-wrapper.

div {
    margin-block-start: 2.25rem;
    display: flex;
    align-items: center;
    gap: .75rem;

    svg {
        width: 1.25rem;
        height: 1.25rem;
    }

    p {
        font-size: .875rem;
        line-height: 1.42;
    }
}

Note:
em for letter spacing. -0.0385em is relative to the current font size. So the spacing scales with the text, which is why it works for both the logo and the heading.
logical properties. margin-block and margin-block-start mean “top and bottom” and “top”. They adapt automatically for right-to-left languages.

Output:

Lemon.

A little more clarity. Every day.

Good work
starts here.

A considered space to organize your work, find your focus, and move forward.

Free to get started. Room to grow.

4. Add the Form Heading

Now let’s build the right panel. Add the .registration-form-wrapper after the left panel. It has an eyebrow, a heading with an id, and a short subtitle.

<div class="registration-form-wrapper">
    <p class="eyebrow">Get Started</p>
    <h3 id="registration-form">Create your account</h3>
    <p class="form-subtitle">A fresh space for your next chapter.</p>
</div>

Give the panel a white background and generous padding. Reduce the padding on tablet screens. Then style the heading and subtitle. Add this inside .registration-grid.

.registration-form-wrapper {
    padding: clamp(4rem, calc(1rem + 8.89vw), 9rem);
    background-color: var(--color-surface);
    container-type: inline-size;

    @media (width < 1025px) {
        padding: clamp(2rem, calc(1rem + 5.6vw), 4rem);
    }

    h3 {
        margin-block: .75rem;
        font-weight: 600;
        font-size: 2rem;
        line-height: 1.25;
        letter-spacing: -0.0344em;
        color: var(--color-heading);
    }

    .form-subtitle {
        font-size: .875rem;
        line-height: 1.6;
    }
}

Note:
the heading id. The id on the h3 matters. In the next step, the form points to it with aria-labelledby, so screen readers announce the form as “Create your account”.

Output:

Lemon.

A little more clarity. Every day.

Good work
starts here.

A considered space to organize your work, find your focus, and move forward.

Free to get started. Room to grow.

Get Started

Create your account

A fresh space for your next chapter.

5. Add the Form Fields

Next, add the form inside .registration-form-wrapper. Start with a .form-row that holds the first and last name fields, and then the email field.

<form action="" method="post" aria-labelledby="registration-form">
    <div class="form-row">
        <div class="form-field">
            <label for="first-name">First name</label>
            <input type="text" id="first-name" name="firstName" placeholder="Jane" autocomplete="given-name" required>
        </div>
        <div class="form-field">
            <label for="last-name">Last name</label>
            <input type="text" id="last-name" name="lastName" placeholder="Smith" autocomplete="family-name" required>
        </div>
    </div>

    <div class="form-field">
        <label for="email">Email address</label>
        <input type="email" id="email" name="email" placeholder="you@example.com" autocomplete="email" required>
    </div>
</form>

Note:
autocomplete. Values like given-name and email let the browser autofill the field for the user. It is a small attribute that saves a lot of typing.

Add a top margin to the form. Use a two-column grid on .form-row, and collapse it to one column on smaller screens. Then style the labels and inputs. Add this inside .registration-form-wrapper.

form {
    margin-block-start: 2rem;
    color: var(--color-text-primary);

    .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 1.25rem;

        @media (width < 992px) {
            grid-template-columns: 1fr;
        }
    }

    .form-field {
        margin-block-end: 1.25rem;

        label {
            font-weight: 500;
            font-size: .875rem;
            line-height: 1.42;
            color: var(--color-heading);
        }

        input {
            width: 100%;
            margin-block-start: .5rem;
            padding: .75rem .875rem;
            border-radius: 0.375rem;
            border: 1px solid var(--color-border);

            &::placeholder {
                font-size: .875rem;
                line-height: 1.42;
            }
        }
    }
}

I used a similar field and label style in my Contact Form HTML CSS JavaScript post, so check that one out if you want to see inline validation messages too.

Output:

Lemon.

A little more clarity. Every day.

Good work
starts here.

A considered space to organize your work, find your focus, and move forward.

Free to get started. Room to grow.

Get Started

Create your account

A fresh space for your next chapter.

6. Add the Password Field

Now add the password field below the email field. The input sits inside a .password-wrap div, next to a toggle button. The button has two icons, and a visually hidden text label for screen readers.

<div class="form-field">
    <label for="password">Password</label>
    <div class="password-wrap">
        <input type="password" id="password" name="password" placeholder="Create a password" autocomplete="new-password" minlength="8" required aria-describedby="password-rules">
        <button type="button" class="password-toggle">
            <span class="visually-hidden">Show password</span>
            <svg class="icon-eye" aria-hidden="true" focusable="false" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12z" />
                <circle cx="12" cy="12" r="3" />
            </svg>
            <svg class="icon-eye-off" aria-hidden="true" focusable="false" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M17.94 17.94A10.94 10.94 0 0 1 12 19c-7 0-11-7-11-7a19.8 19.8 0 0 1 5.06-5.94" />
                <path d="M9.9 4.24A10.9 10.9 0 0 1 12 5c7 0 11 7 11 7a19.9 19.9 0 0 1-3.17 4.19" />
                <path d="M1 1l22 22" />
            </svg>
        </button>
    </div>
    <p id="password-rules" class="password-hint">• At least 8 characters.</p>
</div>

Set the position property to relative on .password-wrap, so the button can sit inside the input using absolute positioning. Then hide the second icon by default, and swap the icons when the button gets the is-visible class. Add this inside .form-field.

.password-wrap {
    position: relative;

    .password-toggle {
        position: absolute;
        right: .75rem;
        top: .75rem;
        background: none;
        border: none;
        color: black;
        width: 2rem;
        height: 2rem;
        cursor: pointer;

        .icon-eye-off {
            display: none;
        }

        &.is-visible .icon-eye {
            display: none;
        }

        &.is-visible .icon-eye-off {
            display: block;
        }
    }
}

.password-hint {
    margin-block-start: .75rem;
    font-size: .75rem;
    line-height: 1.33;
    opacity: .7;
}

The button only shows an icon, but screen reader users still need a text label. So I put the text in a .visually-hidden span, and use a small helper to hide it from the screen without removing it from the page. Add this inside .password-toggle.

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

Note:
why not display: none? Hiding with display: none removes the text from screen readers too. This helper shrinks the text to a single clipped pixel, so sighted users see nothing, and screen readers still read it.

Output:

Lemon.

A little more clarity. Every day.

Good work
starts here.

A considered space to organize your work, find your focus, and move forward.

Free to get started. Room to grow.

Get Started

Create your account

A fresh space for your next chapter.

• At least 8 characters.

7. Add the Consent Checkbox and the Submit Button

After that, add the consent row and the submit button at the end of the form.

<div class="consent">
    <input type="checkbox" id="terms" name="terms" required>
    <label for="terms">I agree to the <a href="#">Terms of Service</a> and <a href="#">Privacy Policy</a>.</label>
</div>

<button type="submit" class="submit-button">
    Create account
    <svg aria-hidden="true" focusable="false" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M3.33334 10H15.8333M10.8333 15L15.8333 10L10.8333 5" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round" stroke="white" />
    </svg>
</button>

Use flexbox on the consent row, so the checkbox and the label sit side by side. Then use the accent-color property to tint the checkbox with the primary color. For the button, use flexbox with the justify content property set to center, so the text and the arrow stay centered. Add this inside form.

.consent {
    font-size: .875rem;
    line-height: 1.5;
    margin-block-end: 1.25rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    opacity: .9;

    input {
        width: 1.25rem;
        height: 1.25rem;
        border-radius: 0.125rem;
        accent-color: var(--color-primary);
    }

    a {
        font-weight: 500;
        color: var(--color-primary);
        text-decoration: none;
        transition: color .2s;

        &:hover {
            color: var(--color-heading);
        }
    }
}

.submit-button {
    width: 100%;
    padding: .875rem 1.25rem;
    background-color: var(--color-primary);
    color: var(--color-surface);
    border: none;
    border-radius: .375rem;
    font-size: .875rem;
    line-height: 1.42;
    font-weight: 600;
    transition: background-color .2s;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: .75rem;

    &:hover {
        background-color: var(--color-heading);
    }
}

Note:
accent-color. One line recolors native checkboxes, radio buttons, and sliders. You do not need to build a custom checkbox just to match your brand color.

Finally, add a clear focus ring, since keyboard users need to see where they are. I am using :focus-visible, so the ring shows for keyboard focus, and not for every mouse click. Add this inside form.

input:focus-visible,
.password-toggle:focus-visible,
.submit-button:focus-visible,
.consent a:focus-visible {
    outline: none;
    border: 1px solid var(--color-primary);
    box-shadow: 0px 0px 0px 3px hsla(214, 96%, 93%, 1);
}

Note:
:focus vs :focus-visible. :focus fires on every click. :focus-visible fires only when the browser thinks the user needs to see focus, like when tabbing. Since I removed the default outline, always add your own style, otherwise keyboard users get lost.

Output:

Lemon.

A little more clarity. Every day.

Good work
starts here.

A considered space to organize your work, find your focus, and move forward.

Free to get started. Room to grow.

Get Started

Create your account

A fresh space for your next chapter.

• At least 8 characters.

8. Toggle the Password with JavaScript

Last, link script.js before the closing body tag. Wait for the page to load, then select the section, the toggle button, the password input, and the hidden label. If any of them is missing, stop early with a return, so the script never throws an error.

Then listen for clicks on the button. Check if the input type is password. If it is, switch the type to text, and change the hidden label to “Hide password”. Otherwise, switch back. Lastly, toggle the is-visible class, so the CSS swaps the icons.

document.addEventListener("DOMContentLoaded", () => {
    const section = document.querySelector('.registration-section');
    const toggle = section?.querySelector('.password-toggle');
    const password = section?.querySelector('#password');
    const toggleLabel = toggle?.querySelector('.visually-hidden');

    if (!section || !toggle || !password || !toggleLabel) return;

    toggle.addEventListener('click', () => {
        const show = password.type === 'password';
        password.type = show ? 'text' : 'password';
        toggleLabel.textContent = show ? 'Hide password' : 'Show password';
        toggle.classList.toggle('is-visible', show);
    });
});

Note:
optional chaining (?.). section?.querySelector(…) returns undefined instead of crashing when section is null. It makes the guard on the next line safe.
updating the label. Changing the hidden text is what tells screen reader users the button now hides the password. A visual icon swap alone would not reach them.

Output:

Lemon.

A little more clarity. Every day.

Good work
starts here.

A considered space to organize your work, find your focus, and move forward.

Free to get started. Room to grow.

Get Started

Create your account

A fresh space for your next chapter.

• At least 8 characters.


Final Source Code for Registration Form in HTML:

HTML

<section class="registration-section">
    <div class="registration-container">
        <div class="registration-grid">
            <div class="registration-content-wrapper">
                <a href="#">Lemon.</a>
                <p class="eyebrow">A little more clarity. Every day.</p>
                <h2>Good work<br>
                    starts here.</h2>
                <p class="registration-description">A considered space to organize your work,
                    find your focus, and move forward.</p>
                <div>
                    <svg aria-hidden="true" focusable="false" width="100%" height="100%" viewBox="0 0 24 24" fill="none"
                        xmlns="http://www.w3.org/2000/svg">
                        <rect x="0.5" y="0.5" width="23" height="23" rx="11.5" stroke="#B7C9DF" />
                        <path d="M6.16666 12L9.49999 15.3333L17.8333 7" stroke-width="1.33333" stroke-linecap="round"
                            stroke-linejoin="round" stroke="#355577" />
                    </svg>
                    <p>Free to get started. Room to grow.</p>
                </div>
            </div>
            <div class="registration-form-wrapper">
                <p class="eyebrow">Get Started</p>
                <h3 id="registration-form">Create your account</h3>
                <p class="form-subtitle">A fresh space for your next chapter.</p>
                <form action="" method="post" aria-labelledby="registration-form">
                    <div class="form-row">
                        <div class="form-field">
                            <label for="first-name">First name</label>
                            <input type="text" id="first-name" name="firstName" placeholder="Jane"
                                autocomplete="given-name" required>
                        </div>
                        <div class="form-field">
                            <label for="last-name">Last name</label>
                            <input type="text" id="last-name" name="lastName" placeholder="Smith"
                                autocomplete="family-name" required>
                        </div>
                    </div>

                    <div class="form-field">
                        <label for="email">Email address</label>
                        <input type="email" id="email" name="email" placeholder="you@example.com" autocomplete="email"
                            required>
                    </div>

                    <div class="form-field">
                        <label for="password">Password</label>
                        <div class="password-wrap">
                            <input type="password" id="password" name="password" placeholder="Create a password"
                                autocomplete="new-password" minlength="8" required aria-describedby="password-rules">
                            <button type="button" class="password-toggle">
                                <span class="visually-hidden">Show password</span>
                                <svg class="icon-eye" aria-hidden="true" focusable="false" viewBox="0 0 24 24"
                                    fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                    stroke-linejoin="round">
                                    <path d="M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12z" />
                                    <circle cx="12" cy="12" r="3" />
                                </svg>
                                <svg class="icon-eye-off" aria-hidden="true" focusable="false" viewBox="0 0 24 24"
                                    fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                    stroke-linejoin="round">
                                    <path
                                        d="M17.94 17.94A10.94 10.94 0 0 1 12 19c-7 0-11-7-11-7a19.8 19.8 0 0 1 5.06-5.94" />
                                    <path d="M9.9 4.24A10.9 10.9 0 0 1 12 5c7 0 11 7 11 7a19.9 19.9 0 0 1-3.17 4.19" />
                                    <path d="M1 1l22 22" />
                                </svg>
                            </button>
                        </div>
                        <p id="password-rules" class="password-hint">• At least 8 characters.</p>
                    </div>

                    <div class="consent">
                        <input type="checkbox" id="terms" name="terms" required>
                        <label for="terms">
                            I agree to the <a href="#">Terms of Service</a> and <a href="#">Privacy
                                Policy</a>.
                        </label>
                    </div>

                    <button type="submit" class="submit-button">
                        Create account
                        <svg aria-hidden="true" focusable="false" width="20" height="20" viewBox="0 0 20 20" fill="none"
                            xmlns="http://www.w3.org/2000/svg">
                            <path d="M3.33334 10H15.8333M10.8333 15L15.8333 10L10.8333 5" stroke-width="1.33333"
                                stroke-linecap="round" stroke-linejoin="round" stroke="white" />
                        </svg>
                    </button>
                </form>
            </div>
        </div>
    </div>
</section>

CSS

* {
    margin: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: hsla(214, 54%, 39%, 1);
    --color-text-primary: hsla(217, 36%, 18%, 1);
    --color-text-secondary: hsla(215, 22%, 34%, 1);
    --color-heading: hsla(214, 51%, 18%, 1);
    --color-border: hsla(214, 21%, 87%, 1);
    --color-surface: hsla(0, 0%, 100%, 1);
    --color-surface-muted: hsla(210, 22%, 96%, 1);
    --color-surface-accent: hsla(214, 50%, 95%, 1);
}

body {
    font-family: "Inter", sans-serif;
    color: var(--color-text-secondary);
}

.registration-section {
    padding: clamp(1rem, calc(1rem + 1.67vw), 2.5rem);
    background-color: var(--color-surface-muted);

    .registration-container {
        border: 1px solid var(--color-border);
        border-radius: .75rem;
        max-width: 85rem;
        margin-inline: auto;
        overflow: hidden;

        .registration-grid {
            display: grid;
            grid-template-columns: 0.852fr 1fr;

            @media (width < 769px) {
                grid-template-columns: 1fr;
            }

            .eyebrow {
                font-weight: 600;
                font-size: .75rem;
                line-height: 1.33;
                letter-spacing: 0.17em;
                text-transform: uppercase;
            }

            .registration-content-wrapper {
                padding: clamp(1rem, calc(1rem + 3.33vw), 4rem);
                background: var(--color-surface-accent) url('bg-shape.png') bottom right no-repeat;
                min-height: 46rem;
                background-size: 85%;

                @media (width < 1025px) {
                    min-height: 35rem;
                }

                a {
                    text-decoration: none;
                    color: inherit;
                    font-weight: 600;
                    font-size: 1.625rem;
                    line-height: 1.5;
                    letter-spacing: -0.0385em;
                }

                .eyebrow {
                    margin-block-start: clamp(3.5rem, calc(1rem + 5.56vw), 6rem);
                }

                h2 {
                    margin-block: 1.25rem;
                    font-weight: 500;
                    font-size: clamp(2.75rem, calc(1rem + 2.78vw), 3.5rem);
                    line-height: 1.125;
                    letter-spacing: -0.0385em;
                    color: var(--color-heading);
                }

                .registration-description {
                    font-size: 1rem;
                    line-height: 1.75;
                    max-width: 22rem;
                }

                div {
                    margin-block-start: 2.25rem;
                    display: flex;
                    align-items: center;
                    gap: .75rem;

                    svg {
                        width: 1.25rem;
                        height: 1.25rem;
                    }

                    p {
                        font-size: .875rem;
                        line-height: 1.42;
                    }
                }
            }

            .registration-form-wrapper {
                padding: clamp(4rem, calc(1rem + 8.89vw), 9rem);
                background-color: var(--color-surface);

                @media (width < 1025px) {
                    padding: clamp(2rem, calc(1rem + 5.6vw), 4rem);
                }

                h3 {
                    margin-block: .75rem;
                    font-weight: 600;
                    font-size: 2rem;
                    line-height: 1.25;
                    letter-spacing: -0.0344em;
                    color: var(--color-heading);
                }

                .form-subtitle {
                    font-size: .875rem;
                    line-height: 1.6;
                }

                form {
                    margin-block-start: 2rem;
                    color: var(--color-text-primary);

                    .form-row {
                        display: grid;
                        grid-template-columns: 1fr 1fr;
                        column-gap: 1.25rem;

                        @media (width < 992px) {
                            grid-template-columns: 1fr;
                        }
                    }

                    .form-field {
                        margin-block-end: 1.25rem;

                        label {
                            font-weight: 500;
                            font-size: .875rem;
                            line-height: 1.42;
                            color: var(--color-heading);
                        }

                        input {
                            width: 100%;
                            margin-block-start: .5rem;
                            padding: .75rem .875rem;
                            border-radius: 0.375rem;
                            border: 1px solid var(--color-border);

                            &::placeholder {
                                font-size: .875rem;
                                line-height: 1.42;
                            }
                        }

                        .password-wrap {
                            position: relative;

                            .password-toggle {
                                position: absolute;
                                right: .75rem;
                                top: .75rem;
                                background: none;
                                border: none;
                                color: black;
                                width: 2rem;
                                height: 2rem;
                                cursor: pointer;

                                .icon-eye-off {
                                    display: none;
                                }

                                &.is-visible .icon-eye {
                                    display: none;
                                }

                                &.is-visible .icon-eye-off {
                                    display: block;
                                }

                                .visually-hidden {
                                    position: absolute;
                                    width: 1px;
                                    height: 1px;
                                    margin: -1px;
                                    padding: 0;
                                    overflow: hidden;
                                    clip-path: inset(50%);
                                    white-space: nowrap;
                                    border: 0;
                                }
                            }
                        }

                        .password-hint {
                            margin-block-start: .75rem;
                            font-size: .75rem;
                            line-height: 1.33;
                            opacity: .7;
                        }
                    }

                    .consent {
                        font-size: .875rem;
                        line-height: 1.5;
                        margin-block-end: 1.25rem;
                        display: flex;
                        align-items: center;
                        gap: .75rem;
                        opacity: .9;

                        input {
                            width: 1.25rem;
                            height: 1.25rem;
                            border-radius: 0.125rem;
                            accent-color: var(--color-primary);
                        }

                        a {
                            font-weight: 500;
                            color: var(--color-primary);
                            text-decoration: none;
                            transition: color .2s;

                            &:hover {
                                color: var(--color-heading);
                            }
                        }
                    }

                    .submit-button {
                        width: 100%;
                        padding: .875rem 1.25rem;
                        background-color: var(--color-primary);
                        color: var(--color-surface);
                        border: none;
                        border-radius: .375rem;
                        font-size: .875rem;
                        line-height: 1.42;
                        font-weight: 600;
                        transition: background-color .2s;
                        cursor: pointer;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        gap: .75rem;

                        &:hover {
                            background-color: var(--color-heading);
                        }
                    }

                    input:focus-visible,
                    .password-toggle:focus-visible,
                    .submit-button:focus-visible,
                    .consent a:focus-visible {
                        outline: none;
                        border: 1px solid var(--color-primary);
                        box-shadow: 0px 0px 0px 3px hsla(214, 96%, 93%, 1);
                    }
                }
            }
        }
    }
}

JS:

document.addEventListener("DOMContentLoaded", () => {
    const section = document.querySelector('.registration-section');
    const toggle = section?.querySelector('.password-toggle');
    const password = section?.querySelector('#password');
    const toggleLabel = toggle?.querySelector('.visually-hidden');

    if (!section || !toggle || !password || !toggleLabel) return;

    toggle.addEventListener('click', () => {
        const show = password.type === 'password';
        password.type = show ? 'text' : 'password';
        toggleLabel.textContent = show ? 'Hide password' : 'Show password';
        toggle.classList.toggle('is-visible', show);
    });
});

If you have any doubts or stuck somewhere, you can reach out through Coding Yaar's Discord server.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Most Voted
Newest Oldest
0
Would love your thoughts, please comment.x
()
x