Home > Web Front-end > CSS Tutorial > Can CSS `content` property insert HTML, not just text?

Can CSS `content` property insert HTML, not just text?

Barbara Streisand
Release: 2024-12-09 06:38:11
Original
633 people have browsed it

Can CSS `content` property insert HTML, not just text?

Inserting HTML into CSS Content Property

Question:

Can the CSS content property be used to insert HTML code instead of text as :before or :after content?

.header:before {
  content: '<a href="#top">Back</a>';
}
Copy after login

Answer:

Unfortunately, this is not possible. According to the CSS specification:

Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).

This means that string values for the content property are always treated literally and not interpreted as HTML.

Using the CSS example provided with the HTML code below:

The above is the detailed content of Can CSS `content` property insert HTML, not just text?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template