HTML alone can't do this you need some other language in backend to check password. Or you can use javascript which will verify password in frontend but you have to specify password in the code itself only if you are doing it for fun. Otherwise for developing web app with login page you need a backend language such as php or python and database such as mysql or mariadb to store passwords.

Sample code
You need to create two files one for your login form (login.html) and another to redirect after right password is entered (welcome.html).

This code is for login.html

    <!DOCTYPE html>
<html>
<head>
    <title>Login page</title>
</head>
<body>
<form>
    <label for="pswd">Enter your password: </label>
    <input type="password" id="pswd">
    <input type="button" value="Submit" onclick="checkPswd();" />
</form>
<!--Function to check password the already set password is admin-->
<script type="text/javascript">
    function checkPswd() {
        var confirmPassword = "admin";
        var password = document.getElementById("pswd").value;
        if (password == confirmPassword) {
             window.location="welcome.html";
        }
        else{
            alert("Passwords do not match.");
        }
    }
</script>
</body>
</html>

This code is for welcome.html

<!DOCTYPE html>
<html>
<head>
    <title>Welcome page</title>
</head>
<body>
<h1>Welcome!! you entered a right password</h1>
</body>
</html>
Answer from Pratik on Stack Overflow
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ HTML โ€บ Reference โ€บ Elements โ€บ input โ€บ password
<input type="password"> - HTML - MDN Web Docs
Many browsers now implement mechanisms to warn against insecure login forms. The value attribute contains a string whose value is the current contents of the text editing control being used to enter the password. If the user hasn't entered anything yet, this value is an empty string ("").
๐ŸŒ
W3Schools
w3schools.com โ€บ howto โ€บ howto_css_login_form.asp
How To Create a Login Form
Login Form Signup Form Checkout Form Contact Form Social Login Form Register Form Form with Icons Newsletter Stacked Form Responsive Form Popup Form Inline Form Clear Input Field Hide Number Arrows Copy Text to Clipboard Animated Search Search Button Fullscreen Search Input Field in Navbar Login Form in Navbar Custom Checkbox/Radio Custom Select Toggle Switch Check Checkbox Detect Caps Lock Trigger Button on Enter Password Validation Toggle Password Visibility Multiple Step Form Autocomplete Turn off autocomplete Turn off spellcheck File Upload Button Empty Input Validation
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ HTML โ€บ Element โ€บ input โ€บ password
<input type="password"> - HTML: HyperText Markup Language
Many browsers now implement mechanisms to warn against insecure login forms. The value attribute contains a string whose value is the current contents of the text editing control being used to enter the password. If the user hasn't entered anything yet, this value is an empty string ("").
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 74496402 โ€บ basic-html-login-form
Basic HTML login form - Stack Overflow
Basically it was a simple login form that sends the user to a specified URL if the text is correct. Something like if input type text is "custom text" and input type password is "custom text" then input type submit button go to ahref "custom url"
๐ŸŒ
Talkerscode
talkerscode.com โ€บ howto โ€บ html-code-for-login-page-with-username-and-password.php
HTML Code For Login Page With Username And Password
Now, today here our topic is how to make a login page in html in which there is a username and password option. The main requirement in login form is to have an input for id means the username and with a password. After this there is a button of submit this information. There is also two more options in many website like remember me and forgot password. Now, there is a code that is given here below to make a login page with the help of CSS.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ html โ€บ html-login-form
HTML Login Form - GeeksforGeeks
July 23, 2025 - Give the button a clear label describing its action, like "Login" or "Submit". ... Include a "Remember Me" checkbox using the <input> tag with the type attribute set to "checkbox". Add a link to a "Forgot Password" page using the <a> tag. Style the form using CSS for a more appealing look. Close the <form> tag. Add the closing </body> and </html> tags to complete the document.
Top answer
1 of 1
2

DON'T EVER USE IN PRODUCTION - LEARNING PURPOSES ONLY

As this is for learning purposes only and you understand it's not secure, I have gone ahead and written a small snippet that will check against a hard coded username and password. If entered username or password do not match it will alert the user.

I have added comments through out the code to explain what I did and what's going on.

See below

<!-- 
    Added onsubmit attribute to form so that it will trigger the JS function (authenticate). 
    if the function returns false it will prevent the form from submitting 
-->
<form action="loggedin.html" onsubmit="return authenticate()">
      <label for="username">Username</label>
      <!-- added IDs to the inputs -->
      <input
        id="username"
        type="text"
        placeholder="Enter Username"
        name="username"
        required
      />
      <label for="password">Password</label>
      <input
        id="password"
        type="password"
        placeholder="Enter Password"
        name="password"
        required
      />
      <button type="submit">Submit</button>
    </form>
    
    <script>
    
    //Following function gets values of the username and password fields and checks to see if they match a hard coded username and password 
      function authenticate(){
        var authorised;
        
        //get input values
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        
        //check to see if the password and username match
        if(username == "abcd" && password == "pass12345"){
          authorised = true;
        }else{ // username or password do not match
          authorised = false;
          //alert user
          alert("Sorry, password is incorrect.");
        }
        //return result
        return authorised;
      }
    </script>

Find elsewhere
๐ŸŒ
GitHub
gist.github.com โ€บ yukiakt โ€บ eedd8f9f754706347b63d2baa95ca73c
simple login page with html, css, and javascript ยท GitHub
simple login page with html, css, and javascript. GitHub Gist: instantly share code, notes, and snippets.
๐ŸŒ
Medium
medium.com โ€บ @namaajiabubakarsadiq โ€บ building-my-login-form-with-html-css-a-step-forward-in-my-web-journey-5196a50849f7
๐Ÿ” Building My Login Form with HTML & CSS: A Step Forward in My Web Journey | by Abubakar Sadiq Namaaji | Medium
October 19, 2025 - So I decided to design and code a Login Form using only HTML and CSS. It wasnโ€™t my first project, but it was one of the most satisfying ones โ€” because it made me realize how far Iโ€™ve come from writing my first <div> to creating something that actually looks like part of a real website. As always, I started with the foundation. HTML gave my form its structure โ€” a container, input fields for username and password, a submit button, and a simple heading.
๐ŸŒ
W3Schools
w3schools.com โ€บ tags โ€บ att_input_type_password.asp
HTML input type="password"
<!--> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hgroup> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <menu> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <
๐ŸŒ
CodeHim
codehim.com โ€บ home โ€บ collections โ€บ 65+ login page in html with css code sample simple to difficult
65+ Login Page in HTML with CSS Code Sample Simple to Difficult โ€” CodeHim
January 22, 2024 - You can view demo and download HTML and CSS source code for login page that you find fit for your needs. The following is a simple login form that comes with a clean user interface to log in. This login form template has a title, input field for email & password, a link to forget password page, ...
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ article โ€บ creating-a-simple-login-page-using-html-and-css
How to Create a Simple Login Page in HTML with CSS Code
July 9, 2024 - <!DOCTYPE html> <html> <head> <title>Login Form</title> <link rel="stylesheet" type="text/css" href="css/style.css"> </head> <body> <h2>Login Page</h2><br> <div class="login"> <form id="login" method="get" action="login.php"> <label><b>User Name </b> </label> <input type="text" name="Uname" id="Uname" placeholder="Username"> <br><br> <label><b>Password </b> </label> <input type="Password" name="Pass" id="Pass" placeholder="Password"> <br><br> <input type="button" name="log" id="log" value="Log In Here"> <br><br> <input type="checkbox" id="check"> <span>Remember me</span> <br><br> Forgot <a href="#">Password</a> </form> </div> </body> </html> ... Next, write code in CSS to apply some style to the HTML so you can change the look of the login page.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ html-login-form
HTML Login Form - Javatpoint
HTML Login Form - HTML Login Form with html tutorial, tags, anchor, img, div, entity, textarea, marquee, p tag, heading tag, h1, h2, table, formatting, attribute, elements, ol, ul, Input Types, block element tag, inline element tag, html tags, phrase tag, head, body, form, lists, symbols etc.
๐ŸŒ
DotFactory
dofactory.com โ€บ html โ€บ input โ€บ password
HTML input type="password",
<form action="/tutorial/action.html"> <label for="fullname">Username</label><br /> <input type="text" id="username" name="username"><br /> <label for="password">Password</label><br /> <input type="password" id="password" name="password"><br /> <input type="submit" value="Login"> </form> Try it live
๐ŸŒ
CodeWithFaraz
codewithfaraz.com โ€บ home โ€บ blogs โ€บ 30 login form collection with source code in html, css, and javascript
30 Login Form Collection with Source Code in HTML, CSS, and JavaScript
May 8, 2014 - Step-by-step guide for stylish and interactive login buttons. ... Learn how to create a Neon Brick Breaker game using HTML, CSS, and JavaScript. Simple steps for beginners to build a glowing arcade-style game. ... Learn how to make a random password generator using HTML, CSS, and JavaScript. This beginner tutorial includes step-by-step code and tips for strong passwords.
๐ŸŒ
DhiWise
dhiwise.com โ€บ post โ€บ how-to-make-a-login-page-in-html-a-step-by-step-guide
How to Make a Login Page in HTML: A Simple Guide
October 11, 2024 - Using strong password hashing algorithms, enforcing password policies, and providing options for two-factor authentication further enhance the security of your login page. Before diving into the creation process, ensure you have a basic understanding of HTML, CSS, and JavaScript. You'll also need a text editor or Integrated Development Environment (IDE) to write your code ...
๐ŸŒ
W3Schools
w3schools.com โ€บ howto โ€บ howto_js_password_validation.asp
How To Create a Password Validation Form
Login Form Signup Form Checkout Form Contact Form Social Login Form Register Form Form with Icons Newsletter Stacked Form Responsive Form Popup Form Inline Form Clear Input Field Hide Number Arrows Copy Text to Clipboard Animated Search Search Button Fullscreen Search Input Field in Navbar Login Form in Navbar Custom Checkbox/Radio Custom Select Toggle Switch Check Checkbox Detect Caps Lock Trigger Button on Enter Password Validation Toggle Password Visibility Multiple Step Form Autocomplete Turn off autocomplete Turn off spellcheck File Upload Button Empty Input Validation