Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content alt text #1423

Closed
2 of 3 tasks
clarfonthey opened this issue Jul 6, 2024 · 4 comments · Fixed by #1425
Closed
2 of 3 tasks

content alt text #1423

clarfonthey opened this issue Jul 6, 2024 · 4 comments · Fixed by #1425

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Jul 6, 2024

What would you want to propose?

CSS content supports adding an alternative text after a slash, like so:

content: "string" / "alt text";

However, since some browsers don't support this, you can emit an extra version of the content property without the slash, as a backup:

content: "string" "alt text";
content: "string" / "alt text";

Suggested solution

A postcss-content-alt-text plugin could perform this transformation and it could be enabled by postcss-preset-env if any supported browsers don't have the feature.

Additional context

CIU page: https://caniuse.com/mdn-css_properties_content_alt_text
MDN page: https://developer.mozilla.org/en-US/docs/Web/CSS/content#browser_compatibility

Validations

  • Follow our Code of Conduct
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Would you like to open a PR for this feature?

  • I'm willing to open a PR
@clarfonthey clarfonthey added the feature request New feature or request label Jul 6, 2024
@romainmenke
Copy link
Member

Added to CSSDB : https://cssdb.org/#content-alt-text in csstools/cssdb#405

@romainmenke
Copy link
Member

Thank you for opening this issue @clarfonthey!

Shouldn't the fallback be to simply remove the /:

content: "string" "alt text";
content: "string" / "alt text";

This is what MDN suggests: https://developer.mozilla.org/en-US/docs/Web/CSS/content#adding_an_image_with_alternative_text

Erasing the alt text isn't that great for accessibility.

Maybe better if it breaks a bit visually in older browsers versions but that all the content is present?

@clarfonthey
Copy link
Contributor Author

Ah, I wasn't aware that you could just add two strings in the content tag like that; I like that version better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants