Skip to content
Home/Guides/Word Frequency Counter — How to Count Word Occurrences in Text Online
Guide·

Word Frequency Counter — How to Count Word Occurrences in Text

Knowing which words appear most often in your text reveals patterns you cannot see by reading alone. A blog post about "JavaScript performance" should have those keywords appearing throughout the content — but how many times is enough, and how many is too many? A research paper should distribute key terms evenly across sections. A product description should emphasize benefits over features. Word frequency analysis gives you the data to answer these questions objectively.

This guide covers what word frequency counting is, how to implement it in code, how it applies to SEO and content optimization, and the insights you can extract from frequency data.

What Is Word Frequency Analysis?

Word frequency analysis counts how many times each unique word appears in a body of text, then sorts them by occurrence count. The output is a frequency table showing each word, its count, and optionally its percentage of total words (keyword density). Filtering out stop words (the, is, and, a, to) reveals the meaningful content words that define the text's topic.

You would use word frequency analysis for SEO keyword density checking, content topic verification, plagiarism pattern detection, authorship analysis, text mining and topic modeling, competitive content analysis, and vocabulary diversity assessment.

How to Count Word Frequency with FlipMyCase

  1. Open the FlipMyCase Word Frequency Counter.
  2. Paste your text.
  3. The tool instantly shows every unique word sorted by frequency, with count and percentage.
  4. Toggle stop word filtering to focus on meaningful keywords.
  5. Use the results to optimize your content.

For overall text metrics (total word count, sentence count, reading time), use the Word Counter alongside the frequency counter.

Code Examples for Word Frequency Counting

JavaScript

function wordFrequency(text, options = {}) {
  const { ignoreCase = true, filterStopWords = false } = options;
  const stopWords = new Set([
    'the','is','at','which','on','a','an','and','or','but',
    'in','to','for','of','with','it','this','that','from','by',
    'are','was','were','be','been','being','have','has','had',
    'do','does','did','will','would','could','should','may','can',
  ]);

  let words = text.match(/\b[a-zA-Z']+\b/g) || [];
  if (ignoreCase) words = words.map(w => w.toLowerCase());
  if (filterStopWords) words = words.filter(w => !stopWords.has(w.toLowerCase()));

  const freq = {};
  for (const word of words) {
    freq[word] = (freq[word] || 0) + 1;
  }

  const total = words.length;
  return Object.entries(freq)
    .sort((a, b) => b[1] - a[1])
    .map(([word, count]) => ({
      word,
      count,
      percentage: ((count / total) * 100).toFixed(1) + '%',
    }));
}

const text = 'JavaScript is a versatile language. JavaScript can run on servers. JavaScript frameworks like React use JavaScript extensively.';
const results = wordFrequency(text, { filterStopWords: true });
results.slice(0, 5).forEach(r => {
  console.log(`${r.word}: ${r.count} (${r.percentage})`);
});
// javascript: 4 (33.3%)
// language: 1 (8.3%)
// versatile: 1 (8.3%)
// ...

Python

import re
from collections import Counter

STOP_WORDS = {
    'the','is','at','which','on','a','an','and','or','but','in','to',
    'for','of','with','it','this','that','from','by','are','was','were',
    'be','been','being','have','has','had','do','does','did','will',
    'would','could','should','may','can','not','no','so','if','then',
}

def word_frequency(text, filter_stops=False):
    words = re.findall(r"\b[a-zA-Z']+\b", text.lower())
    if filter_stops:
        words = [w for w in words if w not in STOP_WORDS]

    counts = Counter(words)
    total = len(words)

    return [
        {'word': word, 'count': count, 'pct': f'{count/total*100:.1f}%'}
        for word, count in counts.most_common()
    ]

text = """JavaScript is a versatile language. JavaScript can run on servers.
JavaScript frameworks like React use JavaScript extensively."""

results = word_frequency(text, filter_stops=True)
for r in results[:10]:
    print(f"{r['word']:20s} {r['count']:>3d}  ({r['pct']})")

# Analyze a file
with open('article.txt', 'r') as f:
    content = f.read()
file_freq = word_frequency(content, filter_stops=True)
print(f"\nTop 10 keywords in article:")
for r in file_freq[:10]:
    print(f"  {r['word']}: {r['count']} ({r['pct']})")

Go

package main

import (
    "fmt"
    "regexp"
    "sort"
    "strings"
)

type WordCount struct {
    Word  string
    Count int
    Pct   float64
}

func wordFrequency(text string) []WordCount {
    re := regexp.MustCompile(`\b[a-zA-Z']+\b`)
    words := re.FindAllString(strings.ToLower(text), -1)

    freq := make(map[string]int)
    for _, w := range words {
        freq[w]++
    }

    total := float64(len(words))
    result := make([]WordCount, 0, len(freq))
    for word, count := range freq {
        result = append(result, WordCount{word, count, float64(count) / total * 100})
    }

    sort.Slice(result, func(i, j int) bool {
        return result[i].Count > result[j].Count
    })
    return result
}

func main() {
    text := "JavaScript is versatile. JavaScript runs on servers. JavaScript frameworks use JavaScript."
    results := wordFrequency(text)
    for _, r := range results[:5] {
        fmt.Printf("%-15s %3d  (%.1f%%)\n", r.Word, r.Count, r.Pct)
    }
}

Real-World Use Cases

SEO keyword density optimization. After writing a blog post targeting "JavaScript performance," run it through the Word Frequency Counter to verify your target keyword appears at 1-2% density. If it is under 0.5%, the content may not signal relevance to search engines. If it is over 3%, you risk being flagged for keyword stuffing.

Competitive content analysis. Analyze a competitor's top-ranking article by pasting it into the frequency counter. See which terms they emphasize, what topics they cover, and how their keyword distribution compares to yours. This reveals content gaps and over-optimization opportunities.

Academic writing analysis. Research papers should use key terms consistently across all sections. Word frequency analysis reveals whether a term appears only in the introduction and conclusion (suggesting it is not well-integrated) or is distributed evenly throughout the paper.

Brand voice auditing. Analyze your company's published content to see which words dominate your messaging. If "innovative" appears 50 times but "reliable" appears 3 times, your brand voice may not match your intended positioning.

Common Mistakes and Gotchas

Not filtering stop words makes frequency tables useless. Without filtering, "the," "is," "and," and "to" dominate every frequency list. Always filter stop words when you care about meaningful content words. Keep stop words in the analysis when you are studying writing style or readability patterns.

Case sensitivity causes word splits. "JavaScript" and "javascript" should be counted as the same word. Always normalize to lowercase before counting, unless case differences are meaningful in your analysis (e.g., analyzing code where String and string are different).

Word boundary handling varies by implementation. Hyphenated words like "real-time" may count as one word or two depending on your regex. Contractions like "don't" may be split at the apostrophe. Decide on your handling rules before analyzing and apply them consistently.

Keyword density is a guideline, not a formula. There is no magic percentage that guarantees rankings. A 1.5% density for your target keyword is reasonable, but forced repetition hurts readability. Write naturally, then verify with the Word Frequency Counter that your keywords appear sufficiently.

Conclusion

Word frequency analysis turns subjective content assessment into data. Whether you are optimizing for SEO, analyzing competitor content, auditing brand voice, or verifying academic term distribution, frequency counts give you actionable insights.

The FlipMyCase Word Frequency Counter provides instant frequency tables with stop word filtering, sorting, and percentage calculations. For overall text metrics, use the Word Counter. For readability scoring, use the Readability Analyzer. For programmatic analysis, the JavaScript, Python, and Go examples above handle any text corpus.

📊 Try Word Frequency

Free, no signup, runs in your browser. Try it now.

Frequently Asked Questions

How do I count word frequency in text?

Paste your text into the FlipMyCase Word Frequency Counter. The tool instantly counts every word and sorts them by frequency. You see each unique word alongside its count and percentage of total words.

What are stop words and should I filter them?

Stop words are common words like 'the', 'is', 'at', 'and' that carry little meaning. Filtering them reveals the meaningful keywords in your text. The FlipMyCase tool lets you toggle stop word filtering on and off.

Is word frequency the same as keyword density?

Keyword density is a specific word's frequency expressed as a percentage of total words. If 'javascript' appears 15 times in a 1,000-word article, its keyword density is 1.5%. The FlipMyCase tool shows both raw count and percentage.

How is word frequency used in SEO?

Word frequency analysis reveals whether your target keywords appear enough times for relevance signals, whether you are over-optimizing (keyword stuffing), and which terms dominate your content. Aim for 1-2% density for primary keywords.

Free Text Tools