How to add rectangle or other symbols before section name?

You already added titlesec to your tags, so you could use this package. For example like this:

\documentclass[utf8]{article}
\usepackage{titlesec,xcolor}

\titleformat{\section}{\bfseries\Large}{\textcolor{orange}{\rule[-3pt]{5pt}{1em}}}{5pt}{}

\begin{document}
    \section{section I}
        \subsection{subsection I}
    \section{section II}
        \subsection{subsection II}
\end{document}

enter image description here


For example into stix (or fontawesome) fonts there are many nice symbols. I add a alternative MWE for your question.

enter image description here

\documentclass{article}
\usepackage{lipsum,xcolor}
\usepackage{stix}

\def\orr{\rlap{\protect\makebox[-2cm]{$\color{orange}\vrectangleblack$}}}

\begin{document}
\section{\orr section I}
        \subsection{subsection I}
    \section{\orr section II}
        \subsection{subsection II}
\end{document}