CSS Comments

CSS Comments అంటే ఏమిటి?

CSS Comments అనేవి CSS codeలో developer కోసం రాసే notes. Browser commentsను చదివినా, వాటిని pageపై చూపించదు మరియు వాటి ఆధారంగా styling చేయదు.

CSS comment రాయడానికి /* మరియు */ symbols ఉపయోగిస్తాం. Comment ఈ రెండు symbols మధ్యలో ఉంటుంది.

CSS Comment Syntax

/* This is a CSS comment */

CSS Comments ఎందుకు ఉపయోగించాలి?

  • Codeలోని భాగం ఏమి చేస్తుందో గుర్తుంచుకోవడానికి.
  • Long CSS fileను sectionsగా విభజించడానికి.
  • కొంతకాలం ఒక CSS declarationను తాత్కాలికంగా disable చేయడానికి.
  • Teamలోని ఇతర developersకు code గురించి వివరించడానికి.

Single-line మరియు multi-line comments

CSSలో ప్రత్యేకమైన single-line comment syntax లేదు. /* ... */ syntaxను ఒక lineలో లేదా అనేక linesలో ఉపయోగించవచ్చు.

/* Header styles */

/* These styles control the main card.
   The comment can continue across multiple lines. */

Commentను CSS declaration మధ్యలో కూడా ఉంచవచ్చు. కానీ comment symbols సరిగ్గా close చేయాలి.

Commentతో CSSను తాత్కాలికంగా disable చేయడం

ఒక declarationను commentలో పెట్టినప్పుడు browser దాన్ని ignore చేస్తుంది. అందువల్ల ఆ style ప్రస్తుతం apply కాదు. ఇది testingలో ఉపయోగకరం.

Simple Explanation

CSS comment అనేది browser కోసం కాదు, developer కోసం రాసే note. Comment ఎప్పుడూ /*తో మొదలై */తో ముగుస్తుంది.

ఉదాహరణకు, /* Make the heading blue */ అనేది browser pageపై కనిపించదు. Commentలో ఉన్న CSS declaration కూడా apply కాదు.

HTML commentsలా CSSలో // ఉపయోగించకండి. CSSలో సరైన syntax /* comment */ మాత్రమే.

Real-Life Example

ఒక notebookలో ప్రతి chapterకు చిన్న note లేదా label రాస్తే, తర్వాత ఆ chapterను సులభంగా అర్థం చేసుకోవచ్చు. అదే విధంగా CSS comments codeలోని sectionsను గుర్తించడానికి సహాయపడతాయి.

ఉదాహరణకు, ఒక websiteలో header styles, card styles, footer styles వేరుగా ఉంటే, ప్రతి section ముందు comment రాస్తే codeను edit చేయడం సులభం అవుతుంది.

Code Examples

CSS Commentsతో Stylesను వివరించడం

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>CSS Comments</title>
  <style>
    /* Set the page background and text font */
    body {
      background-color: #f2f7ff;
      font-family: Arial, sans-serif;
    }

    /* Style the main heading */
    h1 {
      color: #123b72;
    }

    /* This paragraph color is temporarily disabled */
    p {
      /* color: #333333; */
      font-size: 18px;
    }
  </style>
</head>
<body>
  <h1>CSS Comments</h1>
  <p>Comments help developers understand CSS code.</p>
</body>
</html>

ఈ exampleలో CSS sectionsను వివరించడానికి comments ఉపయోగించాం. body మరియు h1 styles ముందు ఉన్న comments browserలో కనిపించవు. color: #333333; declaration commentలో ఉండటం వల్ల అది apply కాదు. కాబట్టి paragraphకు font size మాత్రమే apply అవుతుంది.

The page has a light blue background. The heading is dark blue. The paragraph is 18 pixels in size and uses the browser's default text color because its color declaration is commented out.

Line-by-Line Explanation

/* Set the page background and text font */
ఇది CSS comment. ఇది developerకు తరువాతి body rule page background మరియు fontను control చేస్తుందని చెబుతుంది. Browser దీన్ని pageపై చూపించదు.
body {
ఈ line HTML pageలోని body elementను select చేసే CSS ruleను ప్రారంభిస్తుంది.
background-color: #f2f7ff;
Page backgroundకు light blue color ఇస్తుంది. ఇది comment కాదు కాబట్టి browser దీన్ని apply చేస్తుంది.
/* Style the main heading */
ఈ comment తరువాతి heading style గురించి developerకు వివరిస్తుంది. Commentకు styling effect ఉండదు.
h1 {
Pageలోని h1 headingను select చేసే ruleను ప్రారంభిస్తుంది.
color: #123b72;
Heading textకు dark blue color ఇస్తుంది.
/* This paragraph color is temporarily disabled */
Paragraph colorను తాత్కాలికంగా disable చేశామని ఈ comment వివరిస్తుంది.
/* color: #333333; */
ఈ declaration పూర్తిగా comment symbols మధ్యలో ఉంది. అందువల్ల browser దీన్ని ignore చేస్తుంది మరియు paragraphకు ఈ color apply కాదు.
font-size: 18px;
ఈ declaration commentలో లేదు. అందువల్ల paragraph text size 18 pixelsగా మారుతుంది.

Try It

Try this CSS code:

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Comment Practice</title>
  <style>
    /* Add a note about the heading style here */
    h1 {
      color: darkgreen;
    }

    /* Temporarily disable this declaration and compare the result */
    p {
      color: #333333;
      font-size: 18px;
    }
  </style>
</head>
<body>
  <h1>My CSS Note</h1>
  <p>Try commenting and uncommenting the color declaration.</p>
</body>
</html>

Try It Yourself »

Practice

Practice: practice_codeలోని h1 rule ముందు heading style గురించి ఒక CSS comment రాయండి. తరువాత p ruleలోని color declarationను commentగా మార్చి browserలో resultను గమనించండి.

Hint: Comment syntax /* comment text */. ఒక declarationను disable చేయడానికి ఆ declaration చుట్టూ comment symbols ఉంచండి.

Common Mistakes

CSSలో // This is a comment అని రాయడం.
CSSలో // valid comment syntax కాదు. బదులుగా /* This is a comment */ ఉపయోగించండి.
Commentను /*తో ప్రారంభించి */తో close చేయకపోవడం.
ప్రతి CSS commentకు opening /* మరియు closing */ రెండూ తప్పనిసరి. Close చేయని comment తరువాతి CSS codeను కూడా ignore చేయవచ్చు.
color: red;ను commentలో పెట్టినా browserలో red color కనిపిస్తుందని అనుకోవడం.
Commentలో ఉన్న declaration browserకు కనిపించదు. Color apply కావాలంటే declarationను comment బయట ఉంచండి.
Commentలో HTML text లేదా CSS code రాసినప్పుడు అది pageపై కనిపిస్తుందని అనుకోవడం.
CSS comments developer notes కోసం మాత్రమే. అవి browser pageపై కనిపించవు.

Interview Questions

CSS comment అంటే ఏమిటి?

Answer: CSS comment అనేది developer కోసం రాసే note. Browser దాన్ని display చేయదు మరియు commentలోని CSSను apply చేయదు.

CSS comment syntax ఏమిటి?

Answer: CSS comment /*తో మొదలై */తో ముగుస్తుంది. ఉదాహరణ: /* Header styles */.

CSS commentsను ఎందుకు ఉపయోగిస్తారు?

Answer: Codeను explain చేయడానికి, sectionsను గుర్తించడానికి మరియు కొన్ని declarationsను తాత్కాలికంగా disable చేయడానికి comments ఉపయోగిస్తారు.

CSSలో // comment syntaxను ఉపయోగించవచ్చా?

Answer: లేదు. సాధారణ CSSలో // valid comment syntax కాదు. /* ... */ syntaxనే ఉపయోగించాలి.

Exam Questions

క్రింది వాటిలో సరైన CSS comment ఏది? (a) // note (b) /* note */ (c) # note

Answer:

(b) /* note */ సరైన CSS comment.

CSS comment browser pageలో కనిపిస్తుందా?

Answer:

లేదు. CSS comment browserలో page contentగా కనిపించదు.

ఒక CSS declarationను తాత్కాలికంగా disable చేయడానికి ఏమి చేయాలి?

Answer:

ఆ declarationను /* మరియు */ మధ్య ఉంచాలి.

CSS comments ఒకే lineలో మాత్రమే ఉండాలా?

Answer:

లేదు. CSS comments ఒక lineలో లేదా అనేక linesలో ఉండవచ్చు.

Quick Revision

  • CSS comment syntax: /* comment */.
  • Comments browserలో కనిపించవు.
  • Commentలో ఉన్న CSS declaration apply కాదు.
  • CSSలో // ఉపయోగించకండి.
  • Code explanation, section labels మరియు temporary testing కోసం comments ఉపయోగించండి.
  • ప్రతి commentను */తో సరిగ్గా close చేయండి.

Test Your Knowledge

Take a short quiz based on this lesson.

10 Questions • Results
Scroll to Top