How to make HTML form

I want to learn HTML and CSS. So anyone can recommend some books for HTML learning.
Can anyone check my coding of login form but is not working properly.

<html>
<body>

<form>
  First name:<br>
  <input type="text" name="firstname">
  <br>
  Last name:<br>
  <input type="text" name="lastname">
</form>

<p>Note that the form itself is not visible.</p>

<p>Also note that the default width of a text input field is 20 characters.</p>

</body>
</html>

@PromoOcodes, what do you want the form to do? You don’t have any submit button, so the form’s contents won’t be submitted. In the <form> tag, you haven’t said where this form’s contents are to be sent to be processed (You need an action="some-processing-file.php" for that), and you haven’t said how the contents are to be sent (You need a method="post" for that).

1 Like

Welcome to the forums, @PromoOcodes.

What do you mean by “not working”? Do you mean that it doesn’t display as you want it to, or it doesn’t submit correctly?

(I’ve removed the link from your post as it didn’t seem to have any relevance to your question, and might have been mistaken for an attempt at self-promotion, which we don’t allow here.)

The form has the following HTML errors (apart from the missing attributes on the form tag already mentioned)

You don’t have the labels correctly marked up in label tags.
Also you should have a wrapper between the form tag and the inputs (usually a fieldset tag)

Possibly useful, but not a requirement (I believe)—at least not these days.

Only not required by web browsers because 95% of the web still uses HTML 3.2 where that requirement did nit yet exist.

The HTML 3.2 and HTML 4 specifications were equally useful to browser creators and web page authors but the HTML 5 specification is only written for the browser creators - we are still waiting for the specification to tell us what part of HTML 5 that web authors should be using for new HTML 5 web pages (for those of us who don’t want to go back to writing HTML 3.2 as the specification for the browsers allows). The best I have been able to work out so far is to follow the HTML 4 strict rules but allow those new tags and attributes introduced in HTML 5 that are actually supported by browsers and are useful additions and to disregard all the reintroduced HTML 3.2 tags and the tags that have no browser support (and likely never will).

1 Like

Well, HTML5 (whatever that is!) seems to validate fine without those extra element containers, so for practical purposes, there doesn’t seem to be a need for them these days.

Except when you are writing semantic HTML where they are part of the semantics of any form.

Just to clarify, I was just referring to the extra wrappers between form tag and inputs not being needed, rather than the labels (which should always be used). I used to include a fieldset even for simple forms, but it was pointed out to me that it’s sometimes an accessibility annoyance, and wasn’t needed unless you need to group inputs into sections. So that’s the only time I use it now, and I don’t tend to use extra divs etc. unless I really need them as styling hooks. But I don’t see the extra containers as necessary for “validation”.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.