› Forums › Web Development › HarvardX: CS50W – CS50’s Web Programming with Python and JavaScript › CS50W – Lecture 0 – HTML and CSS › Understanding `placeholder` vs `value` in HTML Inputs (Q&A)
- This topic is empty.
-
AuthorPosts
-
December 30, 2025 at 9:59 am #5908
Context Code
<input name="q" type="text" placeholder="Search Google or type a URL" /> </div> <div class="buttonsindex"> <input type="submit" class="google-submit" value="Google Search" /> <input type="submit" class="google-submit" name="btnI" value="I'm Feeling Lucky" />
Q1. What is the purpose of the
placeholderattribute?Answer:
Theplaceholderattribute provides temporary hint text inside a text input field to guide the user on what to type.In the example:
<input type="text" placeholder="Search Google or type a URL">- The text appears only when the field is empty
- It disappears as soon as the user starts typing
- It is not submitted with the form
The placeholder is purely instructional and does not represent actual input data.
Q2. What is the purpose of the
valueattribute?Answer:
Thevalueattribute represents the actual value of an input element.In submit buttons, it defines the text displayed on the button:
<input type="submit" value="Google Search">For text inputs,
valuewould contain pre-filled data that gets submitted with the form.
Q3. Why does the search input use
placeholderinstead ofvalue?Answer:
Because the search box should start empty, showing only a hint. Ifvaluewere used instead, that text would be treated as real input and submitted unless manually deleted by the user.Using
placeholderkeeps the field empty while still guiding the user.
Q4. Why do the buttons use
valueand notplaceholder?Answer:
Buttons do not accept text input, so they cannot useplaceholder.For buttons:
valuedefines the visible label- The label is part of the form submission
Example:
<input type="submit" value="I'm Feeling Lucky">Without
value, the button would have no visible text.
Q5. What does the
name="q"attribute do in the search input?Answer:
Thenameattribute defines the key used when submitting form data.<input name="q" type="text">When a user searches for
python, the browser sends:?q=pythonGoogle expects the search query under the parameter
q.
Q6. Why does the “I’m Feeling Lucky” button have
name="btnI"?Answer:
Thename="btnI"attribute allows the server to identify which button was clicked.<input type="submit" name="btnI" value="I'm Feeling Lucky">When clicked, the form submits something like:
?q=python&btnI=I'm+Feeling+LuckyGoogle detects
btnIand performs a direct redirect to the top result.
Q7. Does
placeholderever get submitted with the form?Answer:
No.
placeholdertext is never included in form submissions. Only actual user input stored invalue(or typed into the field) is sent.
Q8. Can
valuebe used in text inputs?Answer:
Yes.Example:
<input type="text" value="Default text">In this case:
- The input starts pre-filled
- The text will be submitted unless changed
This is different from
placeholder, which is never treated as real data.
Q9. What is the role of
class="google-submit"in the buttons?Answer:
Theclassattribute is used for CSS styling.<input class="google-submit">It allows you to apply the same visual styling (color, padding, border, etc.) to both buttons without repeating CSS rules.
Final Summary
Attribute Purpose Submitted placeholderUser guidance ❌ No valueActual data / button label ✅ Yes nameKey for form submission ✅ Yes
-
AuthorPosts
- You must be logged in to reply to this topic.

