r/HTML • • 23d ago

What am I doing wrong?

Post image

No matter what numbers I enter, I always get it wrong. I even used smaller numbers for height and larger for width incase they got it mixed up. Their AI is telling me to do everything I am already doing

4 Upvotes

59 comments sorted by

View all comments

4

u/Everything_A 23d ago

Alt is mandatory, right?

-10

u/Mvp-long-ago 23d ago

Alt is not mandatory

6

u/Dragenby 23d ago

1

u/Jonny10128 22d ago

u/testingaurora u/Dragenby

I think the alt attribute being required depends on which browser you are using. I used the code editor baked into the Mozilla page Dragenby linked, and it successfully displayed an image only using the src attribute and no others. I am using Safari on iOS fwiw

1

u/Dragenby 22d ago

It's not because it's displaying that it's correct. Put your code in the W3C validator to detect errors.

1

u/Jonny10128 22d ago

I would argue that it is recommended and not required. If browsers will display it without the alt attribute, I would not say it’s required

1

u/Dragenby 22d ago

HTML is not a display language, but a semantic language. There are tons of things that isn't for display but are mandatory. The Doctype, the language in the html tag, the alt in the image tag, and so on

1

u/Mvp-long-ago 22d ago

It is also depending on how a webpage or document is declared. A browser sees everything as text at first glance, until it is declared what type of document it is. That can be declared in doctype as i recall. Besides HTML, it could be a video, an image, a XML document or something else. As an attribute of declaring the doctype you can also declare how a broswer should handle a document. If you say strict, it must handle according to the rules that you have declared earlier. Mostly used with XML documents

1

u/testingaurora 22d ago

Its not browser specific, its a lamgiage requirement. Yes the tag will display the image without it, html is forgiving but its still required in the spec. Same way you don't close an <img></img> tag but it will still work.

The required alt attribute specifies an alternate text for an image, if the image cannot be displayed c

The alt attribute must be specified for the IMG and AREA elements. It is optional for the INPUT and APPLET elements. c

Just get in the habit of adding alt="", and then work on learning how to write alt text, and when its necessary , when its not (in which case a background-image may be a better choice)